If statement for a struct with 2 conditions

조회 수: 18 (최근 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 CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by