Adding strings in simulink

1 次查看(过去 30 天)
Nico Verbeek
Nico Verbeek 2023-2-21
I'm using a simulink matlab function for the following code:
function [e1s,e2s,crits,users] = fcn(error1,error2)
n=32;
e1 = int2bit(error1,n,true);
e1r = reshape(e1,[8,4]);
e1s = flipud(e1r');
e2 = int2bit(error2,n,true);
e2r = reshape(e2,[8,4]);
e2s = flipud(e2r');
%% error to dashboard part
crits="Critical error:";
users="User error: ";
crits =crits + " test";
I get the following two errors however:
Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.
Component:MATLAB Function | Category:Coder error
Size mismatch (size [1 x 15] ~= size [1 x 20]) in field 'Value'. Function 'MATLAB Function' (#89.286.291), line 17, column 1: "crits" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
I don't understand why the output size suddenly is a vector. Is it just that simulink doesn't like strings?

回答(1 个)

Walter Roberson
Walter Roberson 2023-2-21
you are resizing the string. string literals do not appear to be dynamically sized.
Use a different variable name the first time you assign to crits such as
cbm = "Critical error: ";
crits = cbm + test;
  1 个评论
Nico Verbeek
Nico Verbeek 2023-2-21
编辑:Nico Verbeek 2023-2-21
Thank you, this seems to work. The problem is that I want to add to the already existing string. This is because multiple error messages can be present at the same time. I want to then write if statements that add the different error messages to the string. Is this possible at all?
So I'll give a small snippet of my code (which is sadly just a bunch of if statements, didn't know how to do this differently) to give a better understanding of what I'm trying to do.
if e1s(3:4,:) ==1
crits=crits+" unknown critical error code";
end
if e1s(2,1:3) == 1
crits=crits+" 12v min exceeded";
end
if e1s(1,1) == 1
crits=crits+" Hardware PWM tripzone";
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Block Libraries 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by