Info

This question is closed. Reopen it to edit or answer.

Error in If-expression

1 view (last 30 days)
Sam
Sam on 20 Dec 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
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

Answers (1)

Star Strider
Star Strider on 20 Dec 2014
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 Comments
Image Analyst
Image Analyst on 20 Dec 2014
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
Star Strider on 20 Dec 2014
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.

Tags

Community Treasure Hunt

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

Start Hunting!