Hey. Just starting with matlab here.
Any help would be greatly appreciated. Please include some links to learn more on my mistakes
Why is the 'else' not getting executed?
How do I make the for loop actually of some use?
Because I need to use both the loop and if-else for this...
myorder=[15 40 20 30 28 45 25 35];
week=1:8;
for n=1:length(week)
if myorder>=30
ordercost=(myorder)*(60-(0.1*60));
else
ordercost=(myorder)*60;
end
end
table(week', myorder', ordercost', 'VariableNames',{'Week', 'Orders', 'Cost Ordered'})
sum(ordercost)

 採用された回答

Torsten
Torsten 2022 年 6 月 2 日

0 投票

for n=1:length(week)
if myorder(n)>=30
ordercost(n)=(myorder(n))*(60-(0.1*60));
else
ordercost(n)=(myorder(n))*60;
end
end

1 件のコメント

Capami
Capami 2022 年 6 月 2 日
Thanks.. Much appreciated :)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 6 月 2 日

コメント済み:

2022 年 6 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by