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

1 view (last 30 days)
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.

Accepted Answer

Abderrahim. B
Abderrahim. B on 18 Jul 2022
Edited: Abderrahim. B on 18 Jul 2022
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 Comments
Akashdeep Kaur
Akashdeep Kaur on 18 Jul 2022
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.

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!