フィルターのクリア

How can i add a main line and main column for my table?

2 ビュー (過去 30 日間)
Elias Unk
Elias Unk 2018 年 7 月 22 日
回答済み: dpb 2018 年 7 月 22 日
my table :
'L1' 'B'
'L2' 'B'
'L3' 'A'
'L4' 'C'
'L5' 'B'
'L6' 'C'
'L7' 'C'
'L8' 'A'
How i'd like my table to be :
Line1 Line2
Col1 'L1' 'B'
Col2 'L2' 'B'
Col3 'L3' 'A'
Col4 'L4' 'C'
Col5 'L5' 'B'
Col6 'L6' 'C'
Col7 'L7' 'C'
Col8 'L8' 'A'
Then how can i find all lines with B as column, would something like b_values = table( 'B' == table(:,2))
expected output:
Line1 Line2
Col1 'L1' 'B'
Col2 'L2' 'B'
Col5 'L5' 'B'

採用された回答

dpb
dpb 2018 年 7 月 22 日
Given c is a cell array of your initial data, then
t=cell2table(c,'VariableNames',{'Line1','Line2'},'RowNames',cellstr(num2str([1:size(c,1)].','Col%d')))
t =
8×2 table
Line1 Line2
_____ _____
Col1 'L1' 'B'
Col2 'L2' 'B'
Col3 'L3' 'A'
Col4 'L4' 'C'
Col5 'L5' 'B'
Col6 'L6' 'C'
Col7 'L7' 'C'
Col8 'L8' 'A'
>>
For such data, however, I'd strong recommend using categorical
>> t=table(categorical(c(:,1)),categorical(c(:,2)),'VariableNames',{'Line1','Line2'},'RowNames',cellstr(num2str([1:size(c,1)].','Col%d')))
t =
8×2 table
Line1 Line2
_____ _____
Col1 L1 B
Col2 L2 B
Col3 L3 A
Col4 L4 C
Col5 L5 B
Col6 L6 C
Col7 L7 C
Col8 L8 A
>>

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by