Multiple values in the if-expression

조회 수: 20 (최근 30일)
Sam
Sam 2014년 12월 20일
댓글: Amir Semnani 2021년 3월 19일
My data-file is a (5x5) matrix. Each cell is a struct. In this struct there is 1 datafile (and other files like 'columnsheaders'). I have created a for-loop for 5 measurements en 5 subjects. So I tried to create an 'if-expression' to say that if specific values of that matrix are met, the program should break. But it gives the following error: "The expression to the left of the equals sign is not a valid target for an assignment."
if ((i_testen = 4) & (welke_pp = 1)) | ((i_testen = 4) & (welke_pp = 3)) | ((i_testen = 4) & (welke_pp) = 4) | ((i_testen) = 4 & (welke_pp = 5)) | (i_testen <= 4)
break
RASI = data_sts(welke_pp,i_testen).VideoSignals(:, strcmp('RASI', data_sts(welke_pp,i_testen).VideoSignals_headers));
XY(2,1) = max(RASI)
XY(1,1) = 0;
Begin_Eind_sts.Begin(i_testen) = abs(XY(2,2));
Begin_Eind_sts.Eind(i_testen) = abs(XY(1,2));
close all
end

채택된 답변

Star Strider
Star Strider 2014년 12월 20일
Your program is breaking on i_testen == 1 because at the end of the if statement conditions you have:
(i_testen <= 4)
that will cause the if condition to be true for i_testen == 1.
  댓글 수: 6
Sam
Sam 2014년 12월 22일
Yes!
Star Strider
Star Strider 2014년 12월 22일
Great!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Guillaume
Guillaume 2014년 12월 20일
To compare values together use ==, the equality comparison operator, not = which is the assignment operator
  댓글 수: 3
Sam
Sam 2014년 12월 20일
편집: Sam 2014년 12월 20일
Oh yeah, I see it. I adjusted my code, but now there is another error...
if ((i_testen == 4) & (welke_pp == 1)) | ((i_testen == 4) & (welke_pp == 3)) | ((i_testen == 4) & (welke_pp == 4)) | ((i_testen) == 4 & (welke_pp == 5))
break
else
RASI = data_sts(welke_pp,i_testen).VideoSignals(:, strcmp('RASI', data_sts(welke_pp,i_testen).VideoSignals_headers)); %extract data
XY(2,1) = max(RASI) %get the maximum for RASI
XY(1,1) = 0; %set the minimum to zero
Begin_Eind_sts.Begin(i_testen) = abs(XY(2,2)); %store the data in a struct
Begin_Eind_sts.Eind(i_testen) = abs(XY(1,2));
close all %close all opened figures
end
The error is: "Index exceeds matrix dimensions.
Error in examen_matlabproberenpp1if (line 59) Begin_Eind_sts.Begin(i_testen) = abs(XY(2,2));".
Amir Semnani
Amir Semnani 2021년 3월 19일

Thanks

댓글을 달려면 로그인하십시오.

카테고리

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