how to run a code putting conditions on names cell
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a dataset as follows:
where there are patients and each session of them in the first column, the second is the age, and imagine that the third is my data. I have to do some stuff with this data and I know how I can do it. Imagine now that I have only to plot the third column against the second. What I want is to compute output for all data considering all sessions of each patient. For instead for P10 I want consider the column vectors that go from 1°row to 4°, or for P13.....from 5°to7° etc etc.
PS: I thought to have done well to leave the first column as lonely cell array and the rest of matrix like double.
0 Kommentare
Akzeptierte Antwort
Rik
am 22 Mai 2020
Convert the array to a 3D array: (patient,session,param_index). You can fill missing slots with NaN. That way it is just a matter of indexing to select all sessions from one patient.
If you need help with the conversion, post an example of your data (or your actual data).
6 Kommentare
Rik
am 22 Mai 2020
I showed two examples at the end of the code I posted. What is unclear to you?
This code will change your data array so you don't need to know that lines 1 and 18 belong to the same patient, but you can simply index into your data:
patient=17;session=1;
parameter=4;
%easy:
value=new_data_shape(patient,session,parameter);
%hard:
lookuplabel={sprintf('P%dS%d',patient,session)};%create {'P17S1'}
idx=find(ismember(labels,lookuplabel));
value=data(idx,parameter);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!