Cell arrays as top-level function outputs are not supported in MATLAB Function Block

조회 수: 8(최근 30일)
Yunsik Jung
Yunsik Jung 2021년 7월 7일
댓글: Yunsik Jung 2021년 7월 9일
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

채택된 답변

Jonas
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개)

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by