How can I use Simulink variables in a matlab function ?

1 Ansicht (letzte 30 Tage)
Marine
Marine am 16 Dez. 2014
Beantwortet: Marine am 16 Dez. 2014
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 Kommentare
Marine
Marine am 16 Dez. 2014
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Marine
Marine am 16 Dez. 2014
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.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by