MATLAB: Add row/column names to a matrix

colnamescolumn namedatasetprintmatrow name

Hello! I've created a 24 x 12 matrix (24 is dynamic and will change with each .csv file I run through my for loop) and wanted to attach the years (minyear:maxyear) to the rows and months ('Jan' 'Feb' 'March' 'Apr' 'May' 'June' 'July' 'Aug' 'Sep' 'Oct' 'Nov' 'Dec') to the columns. What is the best way to do this? I've tried using colnames and the dataset feature with no success:
M = rand(5)
dataset({M 'FOO','BAR','BAZ','BUZZ','FUZZ'}, ...
'obsnames', {'ROW1','ROW2','ROW3','ROW4','ROW5'}
Error: Expression or statement is incorrect–possibly unbalanced (, {, or [.
I've also attempted the printrow function
printmat(M, 'My Matrix', 'ROW1 ROW2 ROW3 ROW4 ROW5', 'FOO BAR BAZ BUZZ FUZZ' )
Undefined function 'printmat' for input arguments of type 'double'. Any suggestions? Thanks!

Best Answer

You've missed a bracket
M = rand(5)
dataset({M 'FOO','BAR','BAZ','BUZZ','FUZZ'}, ...
'obsnames', {'ROW1','ROW2','ROW3','ROW4','ROW5'})