how to run a code putting conditions on names cell

조회 수: 2 (최근 30일)
matteo bottoni
matteo bottoni 2020년 5월 22일
댓글: Rik 2020년 5월 22일
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에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by