Using IF and OR statements on multiple conditions

4 ビュー (過去 30 日間)
Ukeje Agwu
Ukeje Agwu 2019 年 3 月 12 日
コメント済み: Guillaume 2019 年 3 月 12 日
Hi, I have a set of conditions I would like to join together to function as just one set of conditions.
for i = 1:length(mydata)
if (mydata(i) == 24)
if (mydata(i+1) == 12)
mydata (i+1) = 'Done';
end
end
end
This works fine, just like my second set of conditions
for i = 1:length(mydata)
if (mydata(i) == 32)
if (mydata(i+1) == 36)
mydata(i+1) = 'Done';
end
end
end
I have also tried to join my individual if statements using &&, and this does not work, so this was my workaround.
However my main problem is that I would like to join these two functions using an || statement, something just like
if (i == 24)
if (i+1 == 12)
i+1 = 'Done'; || if (i == 32)
if (i+1 == 36)
i+1 = 'Done';
end
end
end
end
For some reason, MATLAB does not recognize the symbols, and my output does not change.
Any help would be appreciated.
Context: I want to write the function such that when 12 comes after 24 OR when 36 comes after 32, it shows Done, as in the screenshots below
Screen 1.PNG
to
Screen 2.PNG
  7 件のコメント
Ukeje Agwu
Ukeje Agwu 2019 年 3 月 12 日
The Class is 'struct'
and the size is '1 1800'
Guillaume
Guillaume 2019 年 3 月 12 日
Oh! Well, then isit's very unclear how your data is stored. Best way to clarify it is for you to attach a mat file with mydata in it.
structures are not typically used to store tabular data as you show in your examples.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeScripts についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by