Use a simple array for table row names?

2 ビュー (過去 30 日間)
qmnjb007
qmnjb007 2018 年 1 月 7 日
コメント済み: qmnjb007 2018 年 1 月 7 日
How do I use a simple array (ex. a = [1:1:5]) for the names of row variables in a table?
I find all the different data types in MATLAB to be extremely confusing and poorly documented, and as a result have spend an hour trying to answer this simple question. I know that it involves some conversion of the array to both a cell array AND and character vector, but can't figure it out. Thanks.

採用された回答

Matt J
Matt J 2018 年 1 月 7 日
編集済み: Matt J 2018 年 1 月 7 日
For example,
rownames=arrayfun(@num2str,1:5,'uni',0);
T=array2table(eye(5)); %fake table
>> T.Properties.RowNames=rownames
T =
5×5 table
Var1 Var2 Var3 Var4 Var5
____ ____ ____ ____ ____
1 1 0 0 0 0
2 0 1 0 0 0
3 0 0 1 0 0
4 0 0 0 1 0
5 0 0 0 0 1
  1 件のコメント
qmnjb007
qmnjb007 2018 年 1 月 7 日
Perfect! arrayfun was what i was missing... thanks Matt.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by