If statement for a struct with 2 conditions

25 ビュー (過去 30 日間)
deejt
deejt 2021 年 1 月 19 日
回答済み: Image Analyst 2021 年 1 月 19 日
Hey guys,
I am new to programming and am just doing it out of interest, therefore, I am facing some troubles with probably very basic functions and codes.
So, I have watched several youtube videos and read section about if-statements and have understood the concept.
However, now I have created a struct with four fields (see attached image and file). What I want to do now is to write a code, that would go through all the cells of condition and point and to see whether the conditions are met, to then extract the corresponding value of rt.
For example, extract the value of rt when condition == 'condi1' && point == 40.
This is what I have so far, but it is not working!
for i=1:n
if s.condition(i) == ('condi1') && s.point(i) == (40)
fprintf(s(i).rt)
end
end
Hope you guys can help me out.
Regards

回答 (1 件)

Image Analyst
Image Analyst 2021 年 1 月 19 日
To compare strings use strcmpi() or strcmp() and put the index right after s.
if strcmpi(s(i).condition, 'condi1') && (s.point(i) == 40)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by