I have a text file having 7 columns. First column is UTC time in hours. This file is having data for almost 1 month. i need to separate data day wise and save it to different day . whenever first column value is > than 0.00, a new day is starting

1 view (last 30 days)
please suggest something. i am new to matlab

Accepted Answer

Akbar
Akbar on 4 Jun 2018
Edited: Akbar on 4 Jun 2018
First I have imported your data to matlab using its 'import data' tool. And created a table called 'anci'. Whose size is 5003x7. Where VarName1 is the first column. This code creates a cell Array for each new day. I got a cell Array called 'days' which is of size 37. So, your dataset contains 37 days. When you click on any cell you can see data collected for that particular day. I noticed that most of the days contain about 133 records. Please accept my answer.
%if the difference between previous row and next is
%more than 22, then record the index because thats where a
%new day starts.
k=1;
for i = 2:height(anci)
if abs(anci.VarName1(i) - anci.VarName1(i-1))>22
ind(k) = i;
k=k+1;
end
end
days = cell(length(ind),1); %preallocates dimensions
days{1,:} = anci(1:ind(1)-1,:); % first day
for i = 2:length(ind) % starting from second day
%creates cell array that contains tables; each cell beginning with
%index ind(i) of table anci, ending on index ind(i+1)-1
if i ~= length(ind) %if not last pass
days{i,:} = anci(ind(i):ind(i+1)-1,:);
else
days{i,:} = anci(ind(i):end,:);
end
end
  3 Comments
Akbar
Akbar on 5 Jun 2018
Edited: Akbar on 5 Jun 2018
Because the ind vector doesn't contain the very first row index 1, so i included it manually. And wrote like this: 1:ind(1)-1
days{1,:} = anci(1:ind(1)-1,:); % first day

Sign in to comment.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!