如何创建主表中的许多表并将其存储? [英] How can I create many tables of the main one and store them?

查看:46
本文介绍了如何创建主表中的许多表并将其存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

my_table = readtable('some.csv')

'L1'    'B'
'L2'    'B'
'L3'    'A'
'L4'    'C'
'L5'    'B'
'L6'    'C'
'L7'    'C'
'L8'    'A'

在第二列中,有不同的值B,A和C.我想根据该值创建较小的表,具体取决于右侧的值,因此预期结果将是:

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'

'L3'    'A'
'L8'    'A'

'L4'    'C'
'L6'    'C'
'L7'    'C'

它们中的每一个都存储在不同的变量中以供以后使用.

each of them stored in a different variable for later use.

推荐答案

您可以使用my_table.Variablesmy_table.my_column_header访问表内容.从那里,您可以将值与ABC进行比较;然后创建新表.

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',:));

这篇关于如何创建主表中的许多表并将其存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆