my_table = readtable('some.csv')
'L1' 'B'
'L2' 'B'
'L3' 'A'
'L4' 'C'
'L5' 'B'
'L6' 'C'
'L7' 'C'
'L8' 'A'
In the second column there are different values, B, A, and C. I want to create smaller tables from this one, depending on the value in the right, so the expected outcome would be:
'L1' 'B'
'L2' 'B'
'L5' 'B'
and
'L3' 'A'
'L8' 'A'
and
'L4' 'C'
'L6' 'C'
'L7' 'C'
each of them stored in a different variable for later use.
You can access table contents with my_table.Variables
or my_table.my_column_header
. From there, you can compare the values with A
, B
and C
; then create new tables.
% Get the ABC column.
content=my_table.Variables;
ABC = char(content{:,2});
% Alternatively, if you have the header.
ABC = char(my_table.Line2);
% Create new tables.
tableA = table(my_table(ABC == 'A',:));
tableB = table(my_table(ABC == 'B',:));
tableC = table(my_table(ABC == 'C',:));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments