Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Error in If-expression
1 回表示 (過去 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!