Cell arrays as top-level function outputs are not supported in MATLAB Function Block
22 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Jonas
2021-7-7
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!