If statement for a struct with 2 conditions

26 次查看(过去 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

回答(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 CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by