display string in table

39 ビュー (過去 30 日間)
Elysi Cochin
Elysi Cochin 2022 年 10 月 12 日
コメント済み: Davide Masiello 2022 年 10 月 12 日
row1 = {'a' 'b' 'c' 'd'};
row2 = {'m' 'n' 'o' 'p'};
varnames = {'Col1' 'Col2' 'Col3' 'Col4'};
rownames = {'Row1' 'Row2'};
T = array2table([row1; row2], 'VariableNames', varnames, 'RowNames', rownames);
MyTable = T;
MyTable.Properties.VariableNames = T.Properties.VariableNames;
MyTable.Properties.RowNames = T.Properties.RowNames;
disp(MyTable);
The output of the is
Col1 Col2 Col3 Col4
_____ _____ _____ _____
Row1 {'a'} {'b'} {'c'} {'d'}
Row2 {'m'} {'n'} {'o'} {'p'}
Is it possible to display the table without the single quotes and curly brackets as
Col1 Col2 Col3 Col4
_____ _____ _____ _____
Row1 a b c d
Row2 m n o p

採用された回答

Davide Masiello
Davide Masiello 2022 年 10 月 12 日
row1 = {'a' 'b' 'c' 'd'};
row2 = {'m' 'n' 'o' 'p'};
varnames = {'Col1' 'Col2' 'Col3' 'Col4'};
rownames = {'Row1' 'Row2'};
T = array2table([row1{:}; row2{:}], 'VariableNames', varnames, 'RowNames', rownames);
MyTable = T;
MyTable.Properties.VariableNames = T.Properties.VariableNames;
MyTable.Properties.RowNames = T.Properties.RowNames;
disp(MyTable);
Col1 Col2 Col3 Col4 ____ ____ ____ ____ Row1 a b c d Row2 m n o p
  3 件のコメント
Davide Masiello
Davide Masiello 2022 年 10 月 12 日
I don't think that would be possible with chars that are longer than 1. You could do this though
load var.mat
c = [a;b]
c = 2×6 cell array
{'0.8746±0.0198' } {'0.85384±0.02896'} {'0.85996±0.00886'} {'0.85996±0.00886'} {'0.88568±0.02928'} {'0.8568±0.0203' } {'0.99804±0.00164'} {'0.99802±0.00198'} {'0.99762±0.00238'} {'0.99762±0.00238'} {'0.99838±0.00162'} {'0.99782±0.00182'}
varnames = {'Col1','Col2','Col3','Col4','Col5','Col6'};
rownames = {'a';'b'};
T = array2table(string(c),'VariableNames', varnames, 'RowNames', rownames);
MyTable = T;
MyTable.Properties.VariableNames = T.Properties.VariableNames;
MyTable.Properties.RowNames = T.Properties.RowNames;
disp(MyTable);
Col1 Col2 Col3 Col4 Col5 Col6 _________________ _________________ _________________ _________________ _________________ _________________ a "0.8746±0.0198" "0.85384±0.02896" "0.85996±0.00886" "0.85996±0.00886" "0.88568±0.02928" "0.8568±0.0203" b "0.99804±0.00164" "0.99802±0.00198" "0.99762±0.00238" "0.99762±0.00238" "0.99838±0.00162" "0.99782±0.00182"

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by