how can i program a matfunction block?

I have 3 batteries with me. I want to turn on the switch of the battery corresponding to the highest state of charge I had done following mathfunction. but it shows some errors
function [s1,s2,s3] = fcn(soc1,soc2,soc3)
y = max([soc1,soc2,soc3]);
if y==soc1
s1=1;
s2=0;
s3=0;
elseif y==soc2
s2=1;
s1=0;
s3=0;
elseif y==soc3
s3=1;
s1=0;
s2=0;
end
end

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 4 月 22 日

1 投票

[y, idx] = max([soc1, soc2, soc3]);
s1 = 0; s2 = 0; s3 = 0;
if idx == 1; s1 = 1; end
if idx == 2; s2 = 1; end
if idx == 3; s3 = 1; end

カテゴリ

ヘルプ センター および File ExchangePropulsion and Power Systems についてさらに検索

質問済み:

2018 年 4 月 22 日

回答済み:

2018 年 4 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by