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 Center および File ExchangeSimulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by