Mxarray error using set_param in Function Block Simulink

조회 수: 2 (최근 30일)
Lucas S
Lucas S 2020년 3월 4일
댓글: Lucas S 2020년 3월 5일
Hello !
I have a model which has 3 layers : Subsystem => 2 subsystems => 1 Matlab Function block (in each of both parent subsystem).
The input of the Function block can take the value : 1, 2 or 3 .
I have this code :
y = u;
coder.extrinsic('set_param','get_param','gcs');
parent = get_param(gcs,'parent');
parent2 = get_param(parent, 'parent');
Color = get_param(parent2, 'BackgroundColor');
if u == 3
set_param(get_param(parent, 'parent'),'BackgroundColor','red');
elseif u == 2
if Color == 'red'
else
set_param(get_param(parent, 'parent'),'BackgroundColor','orange');
end
else
if Color == 'red' || Color == 'orange'
else
set_param(get_param(parent, 'parent'),'BackgroundColor','green');
end
end
Explanation :
When the block receive 3 the top Subsystem become red, 2 => Orange and 1 => Green
If he is already red he stay red, if he is already orange he can be red but not green.
Error :
Expected either a logical, char, int, fi, single, or double. Found an mxArray.
MxArrays are returned from calls to the MATLAB interpreter and are not supported inside expressions.
They may only be used on the right-hand side of assignments and as arguments to extrinsic functions.
I don't understand why Color is not a string value as it originate from get_param function.
Thanks for help

채택된 답변

Fangjun Jiang
Fangjun Jiang 2020년 3월 4일
When comparing char array, use strcmp() or isequal(), not to use "==", for example
MyColor='red'
strcmp(MyColor,'green')
isequal(MyColor,'green')
MyColor=='green' will cause error.
  댓글 수: 1
Lucas S
Lucas S 2020년 3월 5일
Ok i don't understand i tried yesterday with strcmp i had the same mxarray error and it worked with isequal today. Thank you !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by