display string in table
37 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Elysi Cochin
am 12 Okt. 2022
Kommentiert: Davide Masiello
am 12 Okt. 2022
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
0 Kommentare
Akzeptierte Antwort
Davide Masiello
am 12 Okt. 2022
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);
3 Kommentare
Davide Masiello
am 12 Okt. 2022
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]
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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!