Cell arrays as top-level function outputs are not supported in MATLAB Function Block
20 views (last 30 days)
Show older comments
Hi, all.
I have a trouble with making an output as a cell array in MATLAB function block in Simulink.
I tried to split a string with '\n' character into the cell array.
My function is shown below, it is simple code to output the cell array.
This cell array contains multiple strings.
function y = fcn(u)
s = 'test\ntest2\ntest3';
s_end = size(s,2);
% sp_s = {};
% sp_s = strsplit(s, '\n');
k = strfind(s, '\n');
sz_k = size(k,2);
out_elems = [];
out_elems = cell(sz_k+1,1);
for i = 1:1:sz_k+1
if i == 1
temp_pos = k(1,i);
temp_str = s(1:temp_pos-1);
elseif i == sz_k+1
pre_temp_pos = k(1,i-1);
temp_str = s(pre_temp_pos+2:s_end);
else
temp_pos = k(1,i);
pre_temp_pos = k(1,i-1);
temp_str = s(pre_temp_pos+2:temp_pos-1);
end
out_elems{i,1} = temp_str;
end
% temp_out = out_elems(1:sz_k+1,1);
y = out_elems;
And I got the following error.
Cell arrays as top-level function outputs are not supported in MATLAB Function Block. Output 'y' is a cell array.
Do you have any idea to solve this error in Simulink?
Thank you in advacned.
Best,
Yun
0 Comments
Accepted Answer
Jonas
on 7 Jul 2021
The input and output of a MATLAB Function block in Simulink needs to be of a data type supported by Simulink. The data types supported by Simulink can be found here. Cell Array is not listed as a supported data type.
You can use cell arrays inside your MATLAB Function but as an output you can only output for example a vector of same data type, or a structure in the form of a Bus Object.
More Answers (0)
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!