## How to select specific cells rows in a column

### Louis Cook (view profile)

on 4 Jan 2019
Latest activity Commented on by Cris LaPierre

### Cris LaPierre (view profile)

on 7 Jan 2019
So i currently have an array that is similar to this on a much larger scale:
1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
I need to write a code that picks out all of the zeros in colum 5 ( the ones that are bolded) but I need it to ignore any subseuent zeros after that (the two rows after)
any help would be great

### per isakson (view profile)

on 5 Jan 2019
Edited by per isakson

### per isakson (view profile)

on 6 Jan 2019

%%
M = [
1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
];
%%
isZero = M(:,5)==0;
% position of first zero
ixb = find( isZero, 1, 'first' );
% position of last zero in first sequence of zeros
ixe = find( not(isZero(ixb:end)), 1, 'first' ) + ixb - 2;
%%
z5 = reshape( M(ixb:ixe,5), 1,[] )
returns
z5 =
0 0 0

Louis Cook

### Louis Cook (view profile)

on 6 Jan 2019
Sorry didnt know to re ask in here :)
So i tried the above option into my code but it wasnt really working so I guess its easier to put my entire code into this and hopefully there is an easier solution :)
1.csv is an example of a file in which there is only one group of 0's so there is no problem
10.csv is an example of where this is two groups of 0's which is causing a problem
thanks for the help
g=9.81; %acceleration due to gravity
num = 1:78;
ext = ".csv";
JumpData = num + ext;
for f=1:length(JumpData );
inputdata=xlsread(JumpData{f});%extract all data from first jump%
idx = find(inputdata(6:3000,5)==0);%finds all the zeros in the z collumn%
zeroMatrix = inputdata(idx,5);%Turns it into a matrix%
oneMatrix=zeroMatrix+1;%adds to to all the zeros%
t=sum(oneMatrix)/100;%sum all of the zeros and turn into miliseconds%
MH(f)=0.5*g*(0.5*(t^2));
MHFinal=MH';
end

### Cris LaPierre (view profile)

on 6 Jan 2019
Edited by Cris LaPierre

### Cris LaPierre (view profile)

on 6 Jan 2019

I'm a fan of readtable, so although it takes more setup, I think overall it handles tables better.
Here is code that just finds the first set of zeros. I'll let you add the rest of your code to it.
for f=1:length(JumpData)
% Set import options to capture information in headerlines
opts = detectImportOptions(JumpData{f});
opts.VariableDescriptionsLine = 3;
opts.VariableNamesLine = 4;
opts.VariableUnitsLine = 5;
opts.DataLines = 6;
% load data into a table
% find first grouping of zeros in Fz
idx = find(data.Fz == 0);
step = find(diff(idx)>1,1)+1;
idx(step:end)=[];
% convert length of zeros to time aloft (each 0 corresponds to 0.01 seconds?)
tm(f) = length(idx)*0.01;
end

Cris LaPierre

### Cris LaPierre (view profile)

on 7 Jan 2019
Answer by Louis Cook on 6 Jan 2019 at 11:55