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

조회 수: 4 (최근 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개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by