How can I use Simulink variables in a matlab function ?

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Marine
Marine il 16 Dic 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.

Accedi per commentare.

Risposta accettata

Marine
Marine il 16 Dic 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.

Più risposte (0)

Categorie

Scopri di più su Simulink in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by