Create dataset from multiple Cell arrays
Ältere Kommentare anzeigen
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 Kommentare
Guillaume
am 22 Jul. 2019
Is the data for each patient always 13 rows (ignoring the 2nd cell), or does that vary per patient?
How is a patient currently identified, is it just the index (1 to 47) of the main cell array?
Anne-Laure GUINET
am 23 Jul. 2019
Guillaume
am 23 Jul. 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.
Akzeptierte Antwort
Weitere Antworten (1)
Shubham Gupta
am 23 Jul. 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 Kommentare
Guillaume
am 23 Jul. 2019
Anne-Laure GUINET comment mistakenly posted as an answer moved here:
Thank you very much for your answers !!!
@Shubham : your solution works perfectly !
Guillaume
am 23 Jul. 2019
No offence meant, but this answer is not very good.
- Hardcoded sizes which means it will only work on the current dataset
- Arrays growing in a loop which means that the performance gets worse and worse as the number of iteration increases
- Numbered variables
Anne-Laure GUINET
am 23 Jul. 2019
Yes, I've understood the structure of your data. You have a Nx1 cell array of patients. You're saying that this cell array now has 34 patients, so the code you've accepted no longer work since it's hardcoded to 47 patients (the one I've given works regardless of the number of patients). Each cell of this cell array is itself of 1x9 cell array.
One of my question was what do these 9 cells correspond to. If we're converting the data into a table, they need names (e.g. Name, Age, Stimuli, Response, whatever you want it to be).
Each of these 9 cells contain what appear to be a 13xN matrix (except cell 2 which is scalar). However, since you've only shown that for one patient, it's possible that for another patient, it's a different number of rows. Hence, why I asked, is it always 13 rows in each matrices.
Anne-Laure GUINET
am 24 Jul. 2019
Bearbeitet: Anne-Laure GUINET
am 24 Jul. 2019
Anne-Laure GUINET
am 24 Jul. 2019
Bearbeitet: Anne-Laure GUINET
am 24 Jul. 2019
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!