Adding strings in simulink

조회 수: 10 (최근 30일)
Nico Verbeek
Nico Verbeek 2023년 2월 21일
편집: 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에서 String에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by