Add Column and Row Labels to Matrix

358 views (last 30 days)
balsip
balsip on 16 May 2017
Commented: Stuart McGarrity on 27 May 2021
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.

Accepted Answer

KL
KL on 16 May 2017
Edited: KL on 16 May 2017
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 Comments
RISHABH RISHABH
RISHABH RISHABH on 22 May 2021
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 on 27 May 2021
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);

Sign in to comment.

More Answers (1)

ASHOK BANERJEE
ASHOK BANERJEE on 20 Nov 2020
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

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!