How to add columns with fixed values to their exact position in the table

7 次查看(过去 30 天)
Hello, I have a table with 16 columns. Some columns have variable value and some have fixed value.
I fixed their values like:
simtable.datacenters(:)="Cloud_1";
Now, This column is at no. 4 in my table. but, when printing output it gets printed at last.
I also want to generate its excel sheet but the columns with fixed values are not added to excel sheet.
Thank you.

采纳的回答

Abderrahim. B
Abderrahim. B 2022-7-18
编辑:Abderrahim. B 2022-7-18
Hi,
Use addvars instead of dot notation to add columns to your table.
Demo:
load patients
T = table(Age,Gender,Smoker) ;
% add a new column to T table before Age
T = addvars(T,LastName,'Before','Age')
T = 100×4 table
LastName Age Gender Smoker ____________ ___ __________ ______ {'Smith' } 38 {'Male' } true {'Johnson' } 43 {'Male' } false {'Williams'} 38 {'Female'} false {'Jones' } 40 {'Female'} false {'Brown' } 49 {'Female'} false {'Davis' } 46 {'Female'} false {'Miller' } 33 {'Female'} true {'Wilson' } 40 {'Male' } false {'Moore' } 28 {'Male' } false {'Taylor' } 31 {'Female'} false {'Anderson'} 45 {'Female'} false {'Thomas' } 42 {'Female'} false {'Jackson' } 25 {'Male' } false {'White' } 39 {'Male' } true {'Harris' } 36 {'Female'} false {'Martin' } 48 {'Male' } true
Hope this helps
  10 个评论
Akashdeep Kaur
Akashdeep Kaur 2022-7-18
Instead of using
simtable.VmName(:)="VM_1" % fixed column data
now i am using
datacenters=repmat("Cloud_1",1,zx);
as suggested by you and the problem is solved.
Thank you for your time and effort.

请先登录,再进行评论。

更多回答(0 个)

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by