how I will check the Conditional statement task?

1 回表示 (過去 30 日間)
Rubel Ahmed
Rubel Ahmed 2020 年 10 月 30 日
コメント済み: Rubel Ahmed 2020 年 11 月 1 日
Hi all,
Suppose I have a time intervel t = 1:1:100;
I can caterize the time intervel as odd and even, So depending on the odd and even,I can execute only to statement inside the conditional if else statement as
if mod(t,2)==1
[task 1]
else
[task 2]
end
But how can we check at least 5 tasks i.e say task 1,task 2........... task 5 for each time step starting from t= 1 to 100?
More clarly,
if t=1, execute task 1
if t=2execute task 2
if t=3, execute task 3
if t=4, execute task 4
if t=5, execute task 5
if t= 6, execute task 1
if t= 7execute task 2
if t= 8, execute task 3
if t=9, execute task 4
if t=10, execute task 5
.
if t= 96, execute task 1
if t=97 execute task 2
if t=98, execute task 3
if t=99, execute task 4
if t=100, execute task 5

採用された回答

John D'Errico
John D'Errico 2020 年 10 月 30 日
The obvious way is to use a switch construct.
for i = 1:100
switch mod(i,5)
case 0
case 1
case 2
case 3
case 4
end
end
If you had more cases, I would probably try to be more creative.
  1 件のコメント
Rubel Ahmed
Rubel Ahmed 2020 年 10 月 30 日
Thanks John D'Errico, Hope this will work in my issue.

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

その他の回答 (1 件)

per isakson
per isakson 2020 年 10 月 30 日
編集済み: per isakson 2020 年 10 月 30 日
With a different interpretation of the word "check"
Modify the script
%%
t = 1;
if mod(t,2)==1
disp('[task 1]')
else
disp('[task 2]')
end
Use Increment Values in Code Sections (a bit down the pge). Select the "1" in t = 1; and right click
Select Increment Value and Run Selection. Increment t and run the section by clicking + .
In the command window you will get
[task 1]
[task 2]
[task 1]
[task 2]
[task 1]
[task 2]
>>
  1 件のコメント
Rubel Ahmed
Rubel Ahmed 2020 年 11 月 1 日
I need to do more tasks(about 50 tasks) , Is it possible to make in creative way ?

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

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by