excel if statement to matlab

8 ビュー (過去 30 日間)
Engineer Undergoing
Engineer Undergoing 2021 年 7 月 30 日
コメント済み: Rik 2021 年 8 月 2 日
hi
so i know there are many efieciant ways to do things on matlab without the need to use the if statement, and I was wondering if someone could help out on converting this excel formula/code to matlab without the need for a double if statements
=IF(AND(E5=0,E4<>0),F4+1,F4)

採用された回答

Monika Jaskolka
Monika Jaskolka 2021 年 7 月 30 日
編集済み: Monika Jaskolka 2021 年 7 月 30 日
I don't see that a "double if" is necessary:
x = 0;
if (~E5 && E4)
x = F4 + 1;
else
x = F4;
end
If you are asking for a one line conditional assignment like below, Matlab doesn't support this syntax
condition ? true-expression : false-expression
  6 件のコメント
Rik
Rik 2021 年 8 月 2 日
@Monika Jaskolka Consider teaching yourself to use numel instead of length. It is never a worse option, and it might save you from a difficult bug hiding in your program due to array input (instead of vector inputs).

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Find more on Data Import from MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by