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!

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 25일

4 개 추천

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

댓글 수: 7

Theodore
Theodore 2013년 7월 25일
Can't believe that was my problem! Thanks for catching that!
ahmed
ahmed 2013년 10월 21일
편집: Azzi Abdelmalek 2013년 10월 21일
I have an question regarding to this code, In case of adding only columns name to the matrix ? If i replaced { 'ROW1','ROW2','ROW3','ROW4','ROW5'} by {''}.. It did not work for me . any suggestions ??
M = rand(5)
dataset({M 'FOO','BAR','BAZ','BUZZ','FUZZ'})
Thx for quick answer. But i got this message : Error using ==> dataset.dataset>dataset.dataset at 256 Must have one variable name for each column when creating multiple variables from an array.
I have a matrix (100*14),I need to name the (14 cloumns with 14 labels ):
I used this one
dataset({mat1 'ROW1', 'ROW2', 'ROW3', 'ROW4', 'ROW5', 'FOO', 'BAR', 'BAZ', 'BUZZ'})
Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 21일
Then use 14 names instead of the 9 names you've used above
ahmed
ahmed 2013년 10월 22일
opsss. I thought that I am using 14 :).. Thx alot.
ahmed
ahmed 2013년 10월 22일
I have an extra question. Now its working great. but i want to save thses results into xls file, I tried this export(mat1,'XLSFile','mat1.xlsx') but I got this ndefined function or method 'export' for input arguments of type 'double'.
Error in ==> BIST1 at 52 export(mat1,'XLSFile','mat1.xlsx') .. Is there any clean way to convert to xls before name the lables and name them after xls conversion then using matlab to handle this ??

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2013년 7월 25일

댓글:

2013년 10월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by