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

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Abderrahim. B
Abderrahim. B il 18 Lug 2022
Modificato: Abderrahim. B il 18 Lug 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 Commenti
Akashdeep Kaur
Akashdeep Kaur il 18 Lug 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.

Accedi per commentare.

Più risposte (0)

Tag

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by