I have a 1x1 structure (EEG) with 42 fields. One of these fields is called event and is a 1x180 structure, with 13 different fields, some of which are strings and some numeric values.
The 4th field of EEG.event is type and it contains strings (i.e. 'preo', 'pred', 'to', 'td', 'po', 'pd').
I would like to keep only those rows of the structure that contain 'preo' in the column EEG.event.type.
My ultimate aim is to create a matrix with all the columns from the structure EEG.event and only the rows with 'preo' in EEG.event.type, plus other columns from other variables.
So far I tried:
S = struct2table(EEG.event);
and it correctly returns a 180x13 table. However I was not able to select only the rows with 'preo' in type. I tried:
A= S(S.type=='preo', :);
and it gives me an error:
Undefined operator '==' for input arguments of type 'cell'.
I also tried:
array(strcmp(S(:, 4), 'preo'), :) = [];
and it gives me this error:
Deletion requires an existing variable.
Then I thought that maybe I should have converted the table into matrix, to directly delete rows from the matrix. I tried:
B = cell2mat(S);
but it returns this error:
Error using cell2mat (line 42)
You cannot subscript a table using only one subscript. Table subscripting requires both row and variable subscripts.
Any suggestion or tip is welcome, because I don't know how to continue.
Example list that I have (only 18 rows here):
13 1 201011 'preo' 2502 201 1 1 'y' 'h' 13 13.9230000000000 13
14 1 201011 'pred' 2684 201 1 1 'y' 'h' 14 14.1049999960000 14
15 1 201012 'to' 2707 201 1 2 'y' 'h' 15 14.1280000000000 15
16 1 201012 'td' 2993 201 1 2 'y' 'h' 16 14.4140000000000 16
17 1 201013 'po' 3019 201 1 3 'y' 'h' 17 14.4400000000000 17
18 1 201013 'pd' 3383 201 1 3 'y' 'h' 18 14.8040000000000 18
55 2 61011 'preo' 8213 61 1 1 'y' 'h' 55 53.9000000000000 55
56 2 61011 'pred' 8522 61 1 1 'y' 'h' 56 54.2089999850000 56
57 2 61012 'to' 8547 61 1 2 'y' 'h' 57 54.2340000000000 57
58 2 61012 'td' 8834 61 1 2 'y' 'h' 58 54.5210000000000 58
59 2 61013 'po' 8858 61 1 3 'y' 'h' 59 54.5450000000000 59
60 2 61013 'pd' 9091 61 1 3 'y' 'h' 60 54.7780000000000 60
85 3 124011 'preo' 13924 124 1 1 'y' 'h' 85 82.4550000000000 85
86 3 124011 'pred' 14159 124 1 1 'y' 'h' 86 82.6899999990000 86
87 3 124012 'to' 14181 124 1 2 'y' 'h' 87 82.7120000000000 87
88 3 124012 'td' 14448 124 1 2 'y' 'h' 88 82.9790000000000 88
89 3 124013 'po' 14470 124 1 3 'y' 'h' 89 83.0010000000000 89
90 3 124013 'pd' 14713 124 1 3 'y' 'h' 90 83.2440000000000 90
Example list that I would like to have (from the 18 rows above):
13 1 201011 'preo' 2502 201 1 1 'y' 'h' 13 13.9230000000000 13
55 2 61011 'preo' 8213 61 1 1 'y' 'h' 55 53.9000000000000 55
85 3 124011 'preo' 13924 124 1 1 'y' 'h' 85 82.4550000000000 85
tableto a.matfile, upload it somewhere, and post a link to it here... Otherwise I don't see how we can reproduce your problem.. - Dev-iL