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 CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by