Concatenate cells: making column and row headers

조회 수: 8(최근 30일)
Hi,
I have a column and a row like this:
col={'cat1'; 'cat2'; 'cat3'}
row={'mouse1' 'mouse2' 'mouse3'}
I would like to make these as column and row headers (eventually for a table) like this such that my table looks like this:
I've attempted to use cat such that:
table=cat(2,col,row)
but it results in an error the dimensions are not consistent..
Thank you so much for your help and please let me know if I am not clear.
  댓글 수: 2
Mich
Mich 2012년 12월 17일
Oh! that is weird, here is the link: http://imgur.com/y0wyb I'm sorry!

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

채택된 답변

Pedro Villena
Pedro Villena 2012년 12월 17일
table(2:numel(row)+1) = row;
table(2:numel(col)+1,1) = col;
  댓글 수: 1
Mich
Mich 2012년 12월 17일
편집: Mich 2012년 12월 17일
That's it! The way that gave me the exact result was:
table(1:numel(row))=row;
table(1:numel(col),1)=col;
Thank you so much!! And to all the helpers, you are awesome!

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

추가 답변(2개)

Honglei Chen
Honglei Chen 2012년 12월 17일
table(2:4) = row;
table(2:4,1) = col;
  댓글 수: 2
Honglei Chen
Honglei Chen 2012년 12월 17일
The code below works fine for me. If you get an error, you may need to make sure that your variable, table, is not defined previously with other dimensions. If that still didn't work out, please post your example with the error message.
>> col = {'a','b','c'}
col =
'a' 'b' 'c'
>> row = {'d','e','f'}
row =
'd' 'e' 'f'
>> table(2:numel(row)+1) = row
table =
[] 'd' 'e' 'f'
>> table(2:numel(col)+1,1) = col
table =
[] 'd' 'e' 'f'
'a' [] [] []
'b' [] [] []
'c' [] [] []

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


Matt Fig
Matt Fig 2012년 12월 17일
편집: Matt Fig 2012년 12월 17일
row={'cat1'; 'cat2'; 'cat3'};
col={'mouse1' 'mouse2' 'mouse3'};
figure
t = uitable('Data',[],...
'ColumnName',col,...
'RowName',row,...
'Position',[20 20 360 100])

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by