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

18 ビュー (過去 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);
temp_pos = k(1,i);
pre_temp_pos = k(1,i-1);
temp_str = s(pre_temp_pos+2:temp_pos-1);
out_elems{i,1} = temp_str;
% 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.


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.
  1 件のコメント
Yunsik Jung
Yunsik Jung 2021 年 7 月 9 日
Hi, Jonas.
Thank you for the comment!


その他の回答 (0 件)


Help Center および File ExchangeSimulink Functions についてさらに検索




Community Treasure Hunt

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

Start Hunting!

Translated by