Search code examples
pythonmatlabsimulink

Matlab cell data can't be referenced from Simulink


From Matlab, I am calling a python function that returns a list, and I want to load those values into an array that I can pass out to Simulink to work with. I can type code into the CommandWindow and get the results I expect:

>> myList = cell(py.myPyModule.myPyFunction());
>> disp(myList);
    [1]    [2]    [3]

>> disp(myList{1});
   1

However, if I put that same code into a Matlab function and call that function from Simulink, that last line gives me an error:

Cell contents reference from a non-cell array object.

Is there some difference in the two cases? I can't figure out any way to actually get the data out in the case where I call a Matlab function from Simulink.


Solution

  • As I understand it, Simulink doesn't support cell arrays. Your function should convert your data to a numeric array to be used in Simulink. You can use the cell2mat function for this.