Concatenate cell arrays in sumulink function block

1 view (last 30 days)
Omkar Karve
Omkar Karve on 13 Feb 2018
Edited: Mark McBroom on 11 Mar 2018
I have a function block that receives two arrays which I convert to cell arrays as below:
T_x={TXFPath_x}; %TXFPath_x is received array of dim 10x1 - this line converts it into a 10x1 double
T_y={TXFPath_y}; %TXFPath_y is received array of dim 10x1 - this line converts it into a 10x1 double
Now I want to concatenate these two cell arrays into a concatenated cell array of 10x2 as:
xy=[T_x; T_y];
This works when I run the .m function file on its own by passing it dummy values. But when I try to run the simulation I get the following error: "Conversion to double from cell is not possible."
Any ideas how to resolve this?
Thanks Omkar
Walter Roberson
Walter Roberson on 13 Feb 2018
The only difference I see in the format is that "10x1 double", which is decoration added at the MATLAB Command line in some of the newer releases; I would not be astonished at all if the decoration is not available in all parts of the MATLAB & Simulink. I see no evidence in what you posted that cell arrays are involved.
If you did create a cell array and it was for an output variable that Simulink has marked as being numeric, Simulink would probably try to convert it to numeric and would fail on doing so, giving the error you are seeing.

Sign in to comment.

Answers (1)

Mark McBroom
Mark McBroom on 11 Mar 2018
Edited: Mark McBroom on 11 Mar 2018
What version of MATLAB are you using? Support for cell arrays in Simulink MATLAB Function block was not added until R2016a. Assuming you are using R2016a or newer ... When Simulink encounters a cell array in a ML Function block it attempts to convert to a matrix or structure. Not sure why Simulink would have a problem with your code, but converting the 2 vectors to cell arrays seems unnecessary. Try eliminating conversion to cell array from your code.
xy=[TXFPath_x; TXFPath_y];

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by