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

4 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Abderrahim. B
Abderrahim. B le 18 Juil 2022
Modifié(e) : Abderrahim. B le 18 Juil 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 commentaires
Akashdeep Kaur
Akashdeep Kaur le 18 Juil 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.
Abderrahim. B
Abderrahim. B le 18 Juil 2022
My pleasure .
Good luck

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by