How to split data into cell

3 views (last 30 days)
Adil Sardar
Adil Sardar on 27 Oct 2021
Commented: Adil Sardar on 28 Oct 2021
In the given excel I have 4 columns I want to split the data with respect to column 1 name as minutes and save the data of the other corresponding columns name with D1, D2, D3.
the condition should be that the data start from zero in column 1 and select the data upto next zero occure. save this data in one cell and again start saving data start from the next zero upto another zero occure.
  7 Comments
Rik
Rik on 27 Oct 2021
I understand what you want, now I want to see if you can translate the text I wrote to code. Think of what should happen step by step. Can you understand why the code you posted didn't work?

Sign in to comment.

Accepted Answer

Mathieu NOE
Mathieu NOE on 27 Oct 2021
hello
could not load your excel file , so I created a dummy one (attached FYI)
the table is splitted into cells according to first zero in minute column
you can also convert tables into other structure if you prefer
hope it helps
clc
clearvars
T = readtable('test1.xlsx');
[m,n] = size(T);
minuts = T.Min;
%% define index corresponding to first zeros (repeating)
ind = find(minuts<eps);
dd = [0; diff(ind)];
p = find(diff(ind)>1);
ind_first_zeros = [ind(1); ind(p+1)];
nb_cells = numel(ind_first_zeros);
%% export table extracts in individual cell
for ci =1:nb_cells
ind_start = ind_first_zeros(ci);
if ci < nb_cells
ind_stop = ind_first_zeros(ci+1)-1;
else % last block of data finish at end of file
ind_stop = m;
end
data_cell{ci} = T(ind_start:ind_stop,:);
end
  1 Comment
Adil Sardar
Adil Sardar on 28 Oct 2021
Thank you it works...

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!

Translated by