splitting data in a table when ever the cell is empty
Mostrar comentarios más antiguos
Hi
I have a long set of data where 100 cycles appear in one colum under each other. Each cycle varies in length.
However they are split up with two empty cells etween each data set.
I want to split the data so the 100 cycles appear next to each other so instead of one colum with all the data there is 100. ( not necerssary but if possible ideally i would want to create a 'cell' numbered 1-100 in first colum with the data in the second colum.)
The following is just an example of what i want.3 cycles side by side.
x
10 20
20 6
30 8
40 7
50 5
40 4
20 6
45 0
4 3
30 6
8 8
10 20 50 5 45 0
20 6 40 4 4 3
30 8 20 6 30 6
40 7 8 8
6 comentarios
Guillaume
el 18 de Mzo. de 2019
Since you mention empty cells, is your data stored in a cell array?
It's much easier if you use valid matlab syntax to describe your data. That way there's no ambiguity. Or attach an example of the data as a mat file.
Other than the empty cells, is all the data numeric? If so, it will be much more efficient to store the final data in a matrix with NaN in the final rows of the shorter cycles. A cell array of scalar numeric uses 15 times more memory than a matrix with the same numbers, and is significantly more difficult to use.
Guillaume
el 18 de Mzo. de 2019
Sufia Fatima's comment mistakenly posted as an answer moved here:
hi
I have imported the data from a .txt file and yes all the data is numerical.
e above example is what the data looks likeTh.
Guillaume
el 18 de Mzo. de 2019
Please, either attach demo text file and the code you used to import it, or attach your data as a mat file.
It's really unclear what form your data is in matlab. You haven't answered my question: is your data stored in a cell array?.
Sufia Fatima
el 18 de Mzo. de 2019
Guillaume
el 18 de Mzo. de 2019
So your data is stored in a matrix. Matrices don't have empty cells. I'm confused by your question.
Sufia Fatima
el 18 de Mzo. de 2019
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 18 de Mzo. de 2019
Editada: Walter Roberson
el 18 de Mzo. de 2019
mask = ~any(indentation_3hr, 2).'; %want row vector
starts = strfind([false mask],[0 1]); %start of non-empty groups
stops = strfind([mask false], [1 0]); %end of non-empty groups
extracted = arrayfun(@(FROM, TO) indentation_3hr(FROM:TO, :), starts, stops, 'uniform', 0);
maxlen = max(arrayfun(@(V) size(V,1), extracted));
FirstN = @(M,N) = M(1:N,:);
PadN = @(M,N) FirstN([M;nan(N, size(M,2))], N);
result = cell2mat( cellfun(@(M) PadN(M, maxlen), extracted(:).', 'uniform', 0) );
2 comentarios
Sufia Fatima
el 19 de Mzo. de 2019
Walter Roberson
el 19 de Mzo. de 2019
FirstN = @(M,N) M(1:N,:);
Categorías
Más información sobre Simulink Functions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!