How can I use Simulink variables in a matlab function ?

조회 수: 1 (최근 30일)
Marine
Marine 2014년 12월 16일
답변: Marine 2014년 12월 16일
I have a Simulink model created, with some Matlab functions in it. The point is that I can not use one of my input from Simulink. Each time I try, I got the same message : 'Expected a scalar. Non-scalars are not supported in IF or WHILE statements, or with logical operators. Instead, use ALL to convert matrix logicals to their scalar equivalents.'. But I saw on documentation that ALL returns a logical array, and I just want to get my values back. Can someone help me solving that ?
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 16일
post your code
Marine
Marine 2014년 12월 16일
function Mode = Mode(in_SoC,SoC_max,SoC_min,Mode1)
Mode = Mode1 ;
if (70<=all(in_SoC)) && (all(in_SoC)<=SoC_max)
Mode = 3;
elseif (40<=all(in_SoC)) && (all(in_SoC)<=70)
Mode = 2;
elseif (SoC_min<=all(in_SoC)) && (all(in_SoC)<=40)
Mode = 1;
end
end
In this code, in_SoC is a Simulink input, and Mode is supposed to be used after to select something, and Mode1 is used as a loop around the function. The others variables are just simple parameters.

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

채택된 답변

Marine
Marine 2014년 12월 16일
I finally find the solution : instead of using ALL (which returns a boolean), I used a=in_SoC(1,1); After putting 'a' everywhere, the function finally works and returns me the godd results.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by