MATLAB: How to make a loop for all participants to delete rows that contain a certain value

lengthtodelete

I would like to delete rows which contain 'ones' in matrices of different sizes, 'ones' indicate bad steps. I want to make a loop to do this for every matrix of 'Gait information' for all the participants, but is is not working yet. The ones can be present in the first and the sixth column of the matrix.
What does work is this example for 1 particular participant:
A = (DATA(15).GAIT_INFO); % 24x11 double
todelete = (A(:,1) == 1) ;
A(todelete,:) = [];
todelete_2 = (A(:,6) == 1);
A(todelete_2,:) = [];
% A has changed to 18 x 11 double which is correct since the original A had 6 rows with ones.
new_Gait_info = A;
DATA(15).GAIT_INFO = new_GI;
I tried the following loop:
ii = 3:size(filenames,1) % for all participants, ii = 1 x 35 double. Starting with 3 since for a certain reason the first 2 arrays are empty
for j = 1:length(DATA(ii).GAIT_INFO);
todelete = (j(:,1) == 1);
j(todelete,:) = [];
todelete_2 = (j(:,6) == 1);
j(todelete_2,:) = [];
end
The error starts at the beginning of the loop j = 1:length(DATA(ii).GAIT_INFO); gives 'Index exceeds array bounds. '
How can I make a loop to check all GAIT.INFO matrices for rows with 'ones' and delete those rows?

Best Answer

Your loop does not seem to make any sense
Having a for loop such as
for j = 1:length(DATA(ii).GAIT_INFO);
means that j will take on values of 1, 2, 3.. up to what ever the termination condition is, in this case
length(DATA(ii).GAIT_INFO)
so j is just an integer. But then you have the statement
todelete = (j(:,1) == 1);
which makes no sense as why would you want to find out the locations where any row, column 1 of an integer equals one, which is what you are doing.
I think you also have some other problem with your termination condition itself.
length(DATA(ii).GAIT_INFO)
I think you probably want to do something like
for j = 3:size(filenames,1)
A = DATA(j).GAIT_INFO;
todelete = A(:,1) == 1 ;
A(todelete,:) = [];
todelete= A(:,6) == 1;
A(todelete,:) = [];
DATA(j).GAIT_INFO = A
end
The above code could be cleaned up further, but I think this should give the idea