If statement for a struct with 2 conditions
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Image Analyst
el 19 de En. de 2021
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 comentarios
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!