Effacer les filtres
Effacer les filtres

how to run a code putting conditions on names cell

1 vue (au cours des 30 derniers jours)
matteo bottoni
matteo bottoni le 22 Mai 2020
Commenté : Rik le 22 Mai 2020
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.

Réponse acceptée

Rik
Rik le 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 commentaires
matteo bottoni
matteo bottoni le 22 Mai 2020
I'm sorry sir but I'm not understanding very well how can I work with 3d matrix and automatizate it for all file. I mean that I don't want to create every output manually. I would like that Matlab should understand that while the number # doesn't change after P then it has to rune the code for that small matrix. If u think that your code is better can you add something else please?
Rik
Rik le 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);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by