Assign one name to three variables in table

1 view (last 30 days)
Ali Tawfik
Ali Tawfik on 5 May 2020
Edited: Cris LaPierre on 5 May 2020
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 Comment
Image Analyst
Image Analyst on 5 May 2020
Edited: Image Analyst on 5 May 2020
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.

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 5 May 2020
Edited: Cris LaPierre on 5 May 2020
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

Categories

Find more on Tables in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!