Borrar filtros
Borrar filtros

Create dataset from multiple Cell arrays

14 visualizaciones (últimos 30 días)
Anne-Laure GUINET
Anne-Laure GUINET el 22 de Jul. de 2019
Comentada: Anne-Laure GUINET el 24 de Jul. de 2019
Hi everybody,
I have a problem to better structure my data...
My results are located in a 47×1 cell array. In fact, each rows is one patient's results. Each patient have nine colums of results, also located in a cell arrays. So, I have 47 patients. For each of them, 9 cell arrays of results.
I would like to create an unique dataset that contains the 3, 4, 5th cell arrays of each patient. After I would like to export this dataset to csv file.
I'm sorry I can't share my code because it's patient's data, but I attach captures of the cell arrays.
Hope you can help me.
Thanks.
  3 comentarios
Anne-Laure GUINET
Anne-Laure GUINET el 23 de Jul. de 2019
In fact I have solved the problem "manually" but it was very long ! If you have an idea to make that in a loop...
I would like to have :
R1 = {[Results{1,1}{1,3} Results{1,1}{1,4} Results{1,1}{1,5}]};
R2 = {[Results{2,1}{1,3} Results{2,1}{1,4} Results{2,1}{1,5}]};
R3 = {[Results{3,1}{1,3} Results{3,1}{1,4} Results{3,1}{1,5}]};
R4 = {[Results{4,1}{1,3} Results{4,1}{1,4} Results{4,1}{1,5}]};
...
R47
47 is a length of "List" which is a cell array with the name of the patients.
And :
AL_SL=cat(1,R1{1,1}(:,1),R2{1,1}(:,1),R3{1,1}(:,1),R4{1,1}(:,1),R5{1,1}(:,1),R6{1,1}(:,1),R7{1,1}(:,1),R8{1,1}(:,1),R9{1,1}(:,1),R10{1,1}(:,1),R11{1,1}(:,1),R12{1,1}(:,1),R13{1,1}(:,1),R14{1,1}(:,1),R15{1,1}(:,1),R16{1,1}(:,1),R17{1,1}(:,1),R18{1,1}(:,1),R19{1,1}(:,1),R20{1,1}(:,1),R21{1,1}(:,1),R22{1,1}(:,1),R23{1,1}(:,1),R24{1,1}(:,1),R25{1,1}(:,1),R26{1,1}(:,1),R27{1,1}(:,1),R28{1,1}(:,1),R29{1,1}(:,1),R30{1,1}(:,1),R31{1,1}(:,1),R32{1,1}(:,1),R33{1,1}(:,1),R34{1,1}(:,1));
AM1_SL=cat(1,R1{1,1}(:,2),R2{1,1}(:,2),R3{1,1}(:,2),R4{1,1}(:,2),R5{1,1}(:,2),R6{1,1}(:,2),R7{1,1}(:,2),R8{1,1}(:,2),R9{1,1}(:,2),R10{1,1}(:,2),R11{1,1}(:,2),R12{1,1}(:,2),R13{1,1}(:,2),R14{1,1}(:,2),R15{1,1}(:,2),R16{1,1}(:,2),R17{1,1}(:,2),R18{1,1}(:,2),R19{1,1}(:,2),R20{1,1}(:,2),R21{1,1}(:,2),R22{1,1}(:,2),R23{1,1}(:,2),R24{1,1}(:,2),R25{1,1}(:,2),R26{1,1}(:,2),R27{1,1}(:,2),R28{1,1}(:,2),R29{1,1}(:,2),R30{1,1}(:,2),R31{1,1}(:,2),R32{1,1}(:,2),R33{1,1}(:,2),R34{1,1}(:,2));
AM2_SL=cat(1,R1{1,1}(:,3),R2{1,1}(:,3),R3{1,1}(:,3),R4{1,1}(:,3),R5{1,1}(:,3),R6{1,1}(:,3),R7{1,1}(:,3),R8{1,1}(:,3),R9{1,1}(:,3),R10{1,1}(:,3),R11{1,1}(:,3),R12{1,1}(:,3),R13{1,1}(:,3),R14{1,1}(:,3),R15{1,1}(:,3),R16{1,1}(:,3),R17{1,1}(:,3),R18{1,1}(:,3),R19{1,1}(:,3),R20{1,1}(:,3),R21{1,1}(:,3),R22{1,1}(:,3),R23{1,1}(:,3),R24{1,1}(:,3),R25{1,1}(:,3),R26{1,1}(:,3),R27{1,1}(:,3),R28{1,1}(:,3),R29{1,1}(:,3),R30{1,1}(:,3),R31{1,1}(:,3),R32{1,1}(:,3),R33{1,1}(:,3),R34{1,1}(:,3));
Comp_SL=[AL_SL AM1_SL AM2_SL];
Guillaume
Guillaume el 23 de Jul. de 2019
" If you have an idea to make that in a loop..."
It's possible that a loop is not even needed and that it can be done easily and efficiently in just a few lines of code.
But to answer you, I need you to answer my questions. So, again:
Is each subcell (corresponding to a patient) always a vector of 13 elements or does the number of elements vary per patient?
Another way to answer that is to give us the output of:
pl = cellfun(@(c) numel(c{1}), Results);
min(pl)
max(pl)
Also, what do the 9 elements correspond to? The easiest way to export your data to csv would be to convert your data to a table, which will require names for the 9 columns, so what should they be named?
A table would also make it much easier for you to analyse the data than cell arrays of cell arrays.

Iniciar sesión para comentar.

Respuesta aceptada

Guillaume
Guillaume el 23 de Jul. de 2019
Editada: Guillaume el 23 de Jul. de 2019
For lack of answers to my questions, here is a more efficient method than the accepted answer:
allpatients = vertcat(Results{:}); %convert in a 47x9 cell array
desireddata = cell2mat(allpatients(:, [3, 4, 5]));
A better way (for further processing) would have been to convert to a table but answers neeeded....
  1 comentario
Anne-Laure GUINET
Anne-Laure GUINET el 24 de Jul. de 2019
It work perfectly !
Thank you very much for your help :)

Iniciar sesión para comentar.

Más respuestas (1)

Shubham Gupta
Shubham Gupta el 23 de Jul. de 2019
I think you can simply achieve this by a for loop. Try this :
AL_SL = [];
AM1_SL = [];
AM2_SL = [];
for i = 1:47
AL_SL = [AL_SL;Results{i,1}{1,3}];
AM1_SL = [AM1_SL;Results{i,1}{1,4}];
AM2_SL = [AM2_SL;Results{i,1}{1,4}];
end
Comp_SL=[AL_SL AM1_SL AM2_SL];
I hope this helps !
  6 comentarios
Anne-Laure GUINET
Anne-Laure GUINET el 24 de Jul. de 2019
Editada: Anne-Laure GUINET el 24 de Jul. de 2019
Thanks Guillaume. It works also for 47 patients but I have to erase some data because of my algo doesn't work for them.
No, the number of rows is different for each patient.
Anne-Laure GUINET
Anne-Laure GUINET el 24 de Jul. de 2019
Editada: Anne-Laure GUINET el 24 de Jul. de 2019
Exept for cell 2 which is always a scalar.
The cell 1 is a time vector.
The cell 2 is a percentage.
The cells 3, 4 , 5 correspond to step length given by different method of calcul.
The cells 6, 7, 8, 9 correspond to time for column 1 and step length for column 2, calculated with 4 different method.
So I have to create a name vector ?
Name=('time', 'percentage'...) % etc for the 9 cells

Iniciar sesión para comentar.

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by