Add Column and Row Labels to Matrix

353 ビュー (過去 30 日間)
balsip
balsip 2017 年 5 月 16 日
コメント済み: Stuart McGarrity 2021 年 5 月 27 日
I'd like to add string data column and row labels (aka "headers") to a 5x13 matrix. I've expanded the matrix to 6x14 with NaNs to accommodate these labels on both the x and y.
I've tried the below threads' approaches, and I'm apparently missing something in each case, and am unable to modify to get them to work for me: https://www.mathworks.com/matlabcentral/newsreader/view_thread/245987 https://www.mathworks.com/matlabcentral/answers/89195-how-to-put-heading-for-columns-of-matrix
I'm really trying to stay out of the Excel world. Truly, I am... but this one is making that temptation hard to resist.
Thank you, everyone.

採用された回答

KL
KL 2017 年 5 月 16 日
編集済み: KL 2017 年 5 月 16 日
Why don't you use table instead?
sample = rand(3,3);
rowNames = {'a','b','c'};
colNames = {'x','y','z'};
sTable = array2table(sample,'RowNames',rowNames,'VariableNames',colNames)
  3 件のコメント
RISHABH RISHABH
RISHABH RISHABH 2021 年 5 月 22 日
What to do if there are 100 columns as if there are 3 like above, we can easily name them as a,b,c. but i have a matrix which has 100 columns and 20 rows. help please
Stuart McGarrity
Stuart McGarrity 2021 年 5 月 27 日
sample=rand(20,100);
rowNames="row_"+ (1:20)'; % Doubles get converted to strings when they are concatenated with them
colNames="col_"+ (1:100);
sTable = array2table(sample,'RowNames',rowNames,'VariableNames',colNames);

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

その他の回答 (1 件)

ASHOK BANERJEE
ASHOK BANERJEE 2020 年 11 月 20 日
I have a problem to label a data array as follows:
Air speed Ambient air temperaure (0 C)
v Ta
(km/h) 5 0 -5 -10 -15 -20 -25 -30 -35
15
30 This space to be filled with (Data array) wind chill temperature,(Twc) given
by the formulae
45 Twc=13.112+0.6215*Ta -11.37*v^0.16+0.3965*Ta*v^0.16
60
75
90

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by