Adding strings in simulink

10 views (last 30 days)
Nico Verbeek
Nico Verbeek on 21 Feb 2023
Edited: Nico Verbeek on 21 Feb 2023
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?

Answers (1)

Walter Roberson
Walter Roberson on 21 Feb 2023
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 Comment
Nico Verbeek
Nico Verbeek on 21 Feb 2023
Edited: Nico Verbeek on 21 Feb 2023
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

Sign in to comment.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!