问题
I have a function in Matlab. I created a python package from it to use in my python code. So far so good. When i call the function in python i received the message:
MatlabRuntimeError: An error occurred when evaluating the result from a function. Details: File C:\Users\Roberto\AppData\Local\Temp\Guilherme\mcrCache9.0.1\classi4\classificado\contagemWGS84.m, line 59, in contagemWGS84 Index exceeds matrix dimensions.
when i go to the line 59 of my code:
plantas(1) = dados{1}(1); %line 59
plantas(1).Diameter = ...
2*sqrt((dados{1}(1).Area*res^2)/pi) + 2*step_erode(1)*res;
for i=1:length(dados)
...
...
...
where dados is an 8x1 struct, dados{1} is a 99x1 struct, and dados{1}(1) is a 1x1 struct matrix and numeric fields. When i run the exact same code directy in matlab, it runs with no problem. When i run in python i got this error.
I am using python 2.7 and Matlab R2016a. Please help.
回答1:
Python (and most numpy) arrays are zero indexed so accessing memeber[1][1] of a 1x1 matrix is asking for the second column of the second row.
来源:https://stackoverflow.com/questions/52155425/python-package-from-library-compiler-matlab-runtime-error-index-exceeds-matrix