How can I use Simulink variables in a matlab function ?

1 vue (au cours des 30 derniers jours)
Marine
Marine le 16 Déc 2014
Réponse apportée : Marine le 16 Déc 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 commentaires
Azzi Abdelmalek
Azzi Abdelmalek le 16 Déc 2014
post your code
Marine
Marine le 16 Déc 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.

Connectez-vous pour commenter.

Réponse acceptée

Marine
Marine le 16 Déc 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.

Plus de réponses (0)

Catégories

En savoir plus sur Modeling dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by