how to run a code putting conditions on names cell

1 次查看(过去 30 天)
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.

采纳的回答

Rik
Rik 2020-5-22
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 个评论
matteo bottoni
matteo bottoni 2020-5-22
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 2020-5-22
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);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by