how to run a code putting conditions on names cell

2 visualizaciones (últimos 30 días)
matteo bottoni
matteo bottoni el 22 de Mayo de 2020
Comentada: Rik el 22 de Mayo de 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.

Respuesta aceptada

Rik
Rik el 22 de Mayo de 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 comentarios
matteo bottoni
matteo bottoni el 22 de Mayo de 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 el 22 de Mayo de 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);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing 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