Assign one name to three variables in table

1 回表示 (過去 30 日間)
Ali Tawfik
Ali Tawfik 2020 年 5 月 5 日
編集済み: Cris LaPierre 2020 年 5 月 5 日
clear all;
t=[33;69;12;13;14;15]
u={'High';'M';'LOW'}
num=2
y=repmat(u,num,1)
i=[0;45]
ii=repelem(i,3)
yy = table(ii,y,t)
I would like the yy table to be only one name for each [high;M;LOW].
So, I would like to have the name 0 for the three elements in u. Is that possible?? Can anyone help?
  1 件のコメント
Image Analyst
Image Analyst 2020 年 5 月 5 日
編集済み: Image Analyst 2020 年 5 月 5 日
I don't understand. There is only one name (High, M, or LOW) for each row:
yy =
6×3 table
ii y t
__ ________ __
0 {'High'} 33
0 {'M' } 69
0 {'LOW' } 12
45 {'High'} 13
45 {'M' } 14
45 {'LOW' } 15
so what's the problem? The "three variables in table" in the table are ii, y, and t -- these are often also called fieldnames or columns - just depends on how people call them.
And what is "the name 0"? Do you mean the values of 0 in rows 1 through 3? Again, each row has only one cell with one word in it for the "y" field of the table.
What do you want your table to look like? Do you want only 2 rows in the table, with values in the "ii" field of 0 and 45? If so, what value would the y column take on? I have no idea so please spell out what you want your table to look like.

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

回答 (1 件)

Cris LaPierre
Cris LaPierre 2020 年 5 月 5 日
編集済み: Cris LaPierre 2020 年 5 月 5 日
It sounds like you want table variable y to be a categorical. If you don't want duplicates, you can set those rows equal to missing.
If I understand what you are asking, I might do the following
t=[33;69;12;13;14;15];
u={'High';'M';'LOW'};
i=[0;45];
ii=repelem(i,3);
yy = table('Size',[6 3],'VariableTypes',["double","categorical","double"]);
yy.Properties.VariableNames = ["ii","y","t"];
yy.ii = ii;
yy.y(1:3)=u;
yy.t = t
ii y t
__ ___________ __
0 High 33
0 M 69
0 LOW 12
45 <undefined> 13
45 <undefined> 14
45 <undefined> 15

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by