Create dataset from multiple Cell arrays
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
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.
Respuesta aceptada
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....
Más respuestas (1)
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
el 24 de Jul. de 2019
Editada: Anne-Laure GUINET
el 24 de Jul. de 2019
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!