convert code from excel to matlab

How do I convert my excel code to matlab? The excel code below contains two "IF" statements and one "AND" statement.
x = IF(AND(2*abs(d)>3*abs(l-n), 2*abs(d)>3*abs(r-n)), 2*abs(d), IF(3*abs(l-n)>3*abs(r-n), 3*abs(l-n), 3*abs(r-n)))

1 件のコメント

Rena Berman
Rena Berman 2021 年 12 月 13 日

(Answers Dev) Restored edit

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

回答 (1 件)

Chunru
Chunru 2021 年 12 月 11 日

0 投票

% x = IF(AND(2*abs(d)>3*abs(l-n), 2*abs(d)>3*abs(r-n)), 2*abs(d), IF(3*abs(l-n)>3*abs(r-n), 3*abs(l-n), 3*abs(r-n)))
if (2*abs(d)>3*abs(l-n)) & (2*abs(d)>3*abs(r-n))
x = 2*abs(d);
elseif (3*abs(l-n)>3*abs(r-n)) & (3*abs(l-n))
x = 3*abs(r-n)));
end

1 件のコメント

Walter Roberson
Walter Roberson 2021 年 12 月 11 日
Note that the above will only work if d and l and n and r are all scalar values. If arrays are being processed then different code would be needed.

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

タグ

質問済み:

2021 年 12 月 11 日

編集済み:

2021 年 12 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by