If statement for a struct with 2 conditions
15 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!