Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Error in If-expression
조회 수: 2 (최근 30일)
이전 댓글 표시
I've made a for-loop for 5 subjects. I've got 2 datafiles. One being 'data_stair_rise' and one being 'data_sts'. Data_stair_rise contains 5 measurements, but data_sts contains only 4 measurements. So when the program goes through the for-loop, it will give an error as soon as the fifth measurement begins for the data_sts-file. So I created an if-expression saying that if the test-value becomes greater than 4, the program should break. But it gives an error that 'RASI' becomes empty when i_testen = 4.
aantal_pp = length(data_stair_rise)
for welke_pp=1:aantal_pp
switch welke_pp
case 1
case 2
case 3
case 4
case 5
end
for i_testen=1:length(data_stair_rise)
RANK = data_stair_rise(welke_pp,i_testen).VideoSignals(:, strcmp('RANK', data_stair_rise(welke_pp, i_testen).VideoSignals_headers))
if i_testen <= 4
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
elseif i_testen > 4
break
end
댓글 수: 0
답변 (1개)
Star Strider
2014년 12월 20일
I cannot follow what you are doing, but if you do not need to use the 5th value of ‘data_stair_rise’, simply subtract 1 from the length calculation:
length(data_stair_rise)-1
wherever you use it.
댓글 수: 3
Image Analyst
2014년 12월 20일
Yeah, longer code with bad indenting and no comments makes the code hard to follow. You can type control-a control-i to have MATLAB fix your indenting. Of course comments have to be manually typed in.
Star Strider
2014년 12월 20일
I certainly agree with I A on the necessity for readable code!
It would seem that you will have to test for the size of the data you are processing in your loop and make appropriate adjustments to the iteration limits. I have no idea how your data are organised, so my only suggestion is to create an outer loop that reads each subject, determines the size, and adjusts the inner loop index limits accordingly.
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!