0

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.

2
  • Your problem might be that for a vector of dimension n, indices run from 0 - n-1 in Python and from 1 - n in Matlab. Commented Sep 3, 2018 at 19:42
  • 1
    i used library compiler from the apps tab in matlab so i think it handle this problem. If i change it the code will be unreadable from the matlab.
    – underfloor
    Commented Sep 3, 2018 at 19:55

1 Answer 1

-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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.