How to create an array of cells in matlab from this data type

Suppose I have 3 patients with profiles, but the profiles do not have the same length. My question is how to create an array of cells from this data (see below), where each record of my array of cells will correspond to one patient profile. Thanks

patient profile

1 2
1 3
1 -2
1 1
1 3
1 2
2 -1
2 -3
2 0
2 -2
3 2
3 2
3 1
3 3
3 2
3 -1
3 -2
3 -3
3 -2
3 -2  
+3
source share
2 answers

Use mat2cell as an engine. I assume that you want to aggregate the results of the second column of the patient profile array depending on the first column. If the profile is in a PP array:

counts = [6;4;10];
C = mat2cell(PP(:,2),counts)
C = 
    [ 6x1 double]
    [ 4x1 double]
    [10x1 double]

See that this step completed the task of extracting data into individual cells.

C{:}
ans =
     2
     3
    -2
     1
     3
     2
ans =
    -1
    -3
     0
    -2
ans =
     2
     2
     1
     3
     2
    -1
    -2
    -3
    -2
    -2

PP , PP. , , , - , . , .

counts = accumarray(PP(:,1),1)
counts =
     6
     4
    10

, , (1: 3), .

+5

accumarray

profile = accumarray( {PP(:,1) },  PP(:,2), [], @(x) {x} );
0

Source: https://habr.com/ru/post/1728898/


All Articles