How do I add character to a string in Simulink/Simevents?

2 ビュー (過去 30 日間)
Ho Jung Kim
Ho Jung Kim 2022 年 8 月 1 日
コメント済み: Walter Roberson 2022 年 8 月 4 日
Is there a way to append characters from array in Simulink/Simevents? I have tried to add characters to an empty string using strcat and append in Simulink/Simevents, but I am getting the following error:
Incorrect size for expression '<output of strcat>': expected [1x0] but found [1x1].
Incorrect size for expression '<output of append>': expected [1x0] but found [1x1].
Is there a way to make this work? or is there another way to append characters to an empty string in Simulink/Simevents? The following is the code I am using. Thank you.
memory is an array with 10 0s.

回答 (1 件)

Mark McBroom
Mark McBroom 2022 年 8 月 4 日
Simulink doesn't like the fact that the variable s grows in length. Try something like this:
.....
s = repat(' ',1,10); % create char array of max size
s_counter = 0;
for c=1:length(entity.memory)
if(entity.memory( c ) ~= 0
s_counter = s_counter + 1;
s(s_counter) = entity.memory( c );
end
end
fprintf('%s\n', s);

カテゴリ

Help Center および File ExchangeDiscrete-Event Simulation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by