MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

Mich
0

Concatenate cells: making column and row headers

Mich
さんによって質問されました 2012 年 12 月 17 日
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 件のコメント

Azzi Abdelmalek
2012 年 12 月 17 日
Your image is invisible
Mich
2012 年 12 月 17 日
Oh! that is weird, here is the link: http://imgur.com/y0wyb I'm sorry!

サインイン to comment.

タグ

製品

3 件の回答

回答者: Pedro Villena
2012 年 12 月 17 日
 採用された回答

table(2:numel(row)+1) = row;
table(2:numel(col)+1,1) = col;

  1 件のコメント

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!

サインイン to comment.


回答者: Honglei Chen
2012 年 12 月 17 日

table(2:4) = row;
table(2:4,1) = col;

  2 件のコメント

Mich
2012 年 12 月 17 日
Unfortunately i get a dimension mismatch error as well. I tried the method under Azzi's comment because with my real dataset I would not know the if it actually ended on the 4th row. Perhaps I am looking for something more like:
table={}
table(2:size(row,2))=row;
table(2:size(col,1),1)=col;
But I get a dimension mismatch.. Thank you for your response!!
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' [] [] []

サインイン to comment.


回答者: Loginatorist
2012 年 12 月 17 日
編集済み: Loginatorist
2012 年 12 月 17 日

row={'cat1'; 'cat2'; 'cat3'};
col={'mouse1' 'mouse2' 'mouse3'};
figure
t = uitable('Data',[],...
'ColumnName',col,...
'RowName',row,...
'Position',[20 20 360 100])

  0 件のコメント

サインイン to comment.



Translated by