Concatenate cell arrays in sumulink function block

1 vue (au cours des 30 derniers jours)
Omkar Karve
Omkar Karve le 13 Fév 2018
Modifié(e) : Mark McBroom le 11 Mar 2018
Hi,
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
  3 commentaires
Omkar Karve
Omkar Karve le 13 Fév 2018
Modifié(e) : Omkar Karve le 13 Fév 2018
There is no value assigned to xy. The first time I try to assign it (xy=[T_x; T_y];) I get this error. Basically xy is a 10x2 double cell array where the first column is T_x and second is T_y. Here is some more info about this: When I create a T_x in matlab workspace and run the function on its own and debug I see this when I hover the cursor over T_x (10x1 double is shown):
But when this function is called via another function I am working on it is unable to pass T_x in a similar way and during debug I see this:
What I am trying to do after receiving data this way is to convert it to the same format as the previous image and then concatenate it horizontally so the xy variable is a 10x2 double as shown below:
Walter Roberson
Walter Roberson le 13 Fév 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.

Connectez-vous pour commenter.

Réponses (1)

Mark McBroom
Mark McBroom le 11 Mar 2018
Modifié(e) : Mark McBroom le 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];

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by