MATLAB: How to eliminate and create new data file

data acquisitionimporting excel dataMATLAB

Hi, I have data which has information for different events, each event has 5 row information. I just want to eleminate this data and delete all of 5 line for that event with respect to some criteria and to create new data file without eleminated data.
A = xlsread('esx.xls');
Mag = cell(1,length(4:5:size(A,1))); %Preallocate Mag for speed
k = 1;
for i= 4:5:size(A,1)
%%%determining magnitudes%%%
Mag{k}=A(i-3,7);
if Mag{k}>5.1
fprintf('Magnitude > 5.7 \n');
end
k=k+1;
end
For example in this case I want to look at 6th row, 7th column value for first event , 11th row 7th column for second, 16th row, 7th column for third and so on (which is defined as Mag{}). If that value is smaller than 5.1, program should delete all 5 line information about that event and write 5 line information of each event with mag value bigger than 5.1 to new xlsx or txt file.
Any suggestions for this code ? I also attached my data in xls format. Thanks in advance.

Best Answer

[num,txt,raw] = xlsread('esx.xls') ;
C1 = txt(:,1) ;
idx0 = strfind(C1,'PDE') ;
idx0 = find(~cellfun(@isempty,idx0)) ;
M = zeros(size(C1)) ;
M(idx0) = num(idx0,7) ;
% get magnitude > 5.1
idx1 = M>5.1 ;
idx2 = idx1 ;
idx = find(idx1) ;
for i = 1:numel(idx)
idx2(idx(i):idx(i)+4) = 1 ;
end
iwant = raw(idx2,:) ;
% write to excel
xlswrite('myfile.xlsx',iwant)