Cell array, getting the columns that have non empty cells in the middle of the column

1 view (last 30 days)
Hi every body. I have a cell array m|x|n , this array is created using a buffer function with an overlap. So i have a 1 dimensional array with some labelings spread in segments and the rest is empty cells. This array i buffer with overlap and an MxN matrix is created. the labelling segments based on the segment length is spread into 2 or three columns of the MxN matrix. But i want to get only the columns where the segment is in the center of the column. Is there any way of achieving it simply? My code is like this:
%creating matrix cell first and second rows are start and stop of anomalie and the third is the name of anomlie.
%
lab={};
lab(:,1)=x1q(1:4:end);
lab(:,2)=x1q(3:4:end);
lab(:,3)=x1q(2:4:end);
%converting the time into seconds and creating an array of start and stop
%time
[~, ~, ~, H, MN, S] = datevec(lab(:,1));
tanom(:,1)=H*3600+MN*60+S;
[~, ~, ~, H, MN, S] = datevec(lab(:,2));
tanom(:,2)=H*3600+MN*60+S+0.5;
% get the middle time of the anomalie window
tanom(:,3)=tanom(1:end,1)+(tanom(1:end,2)-tanom(1:end,1))/2;
%getting the indices of the time nearest to that of the start and stop of
%the anomalie
indt(:,1)=nearestpoint(tanom(:,1),t);%start of anomaly
indt(:,2)=nearestpoint(tanom(:,2),t);%end of anomaly
indt(:,3)=nearestpoint(tanom(:,3),t);%midle of anomaly
%create a cell array with the name of anomalie for the length of the event
%create an empty cell array to hold the anomalies for each row of
%accelereometer data
labelat=cell(length(t),1);
anomalie=zeros(length(t),1);
for i=1:size(tanom,1);
for e=indt(i,1):indt(i,2);
labelat(e)=lab(i,3);
anomalie(e)=1;
end;
end;
labelat(numel(labelat)+1:length(t))=[];%add the rest of empty cells
clear('x1q','lab','Y', 'M', 'D', 'H', 'MN', 'S','e','i');
%Windowing data
labelw = buffer(labelat, wsize, overlap);%window labels
anomw = buffer(anomalie, wsize, overlap);%window labels anomalie

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!