What is the code to add one row above in table?

조회 수: 15 (최근 30일)
Kasih Ditaningtyas Sari Pratiwi
Kasih Ditaningtyas Sari Pratiwi 2017년 11월 7일
답변: Peter Perkins 2017년 11월 16일
Hi! This might be an easy question, but since I am new in matlab, I do not know how to add one row in the first row of table. have a table consist only one column called "timediff" with the size 2143x1 table, I want to make it 2144x1 table, with the addition one row in the first row, and the value is 0. Could you please help me? Thank you in advance

채택된 답변

Birdman
Birdman 2017년 11월 7일
You have to convert the array elements to string, add the specified row and then create a table. An example:
a=5*ones(2143,1);%this is a double array
aTable=array2table(a);%2143x1 table
b=3;%new variable to be added
aNewTable=array2table(str2double([string(b);string(a)]));%2144x1 table
  댓글 수: 3
Birdman
Birdman 2017년 11월 7일
row=input('Enter number of rows\n');
a=5*ones(2143,1);
aTable=array2table(a);
b=3*ones(row,1);
aTablee=array2table(str2double([string(b);string(a)]))
We can make the number of row variable like this, a user data.
Kasih Ditaningtyas Sari Pratiwi
Kasih Ditaningtyas Sari Pratiwi 2017년 11월 7일
It works! Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Peter Perkins
Peter Perkins 2017년 11월 16일
My first observation is that if your table has only one variable, you are likely better off not using a table. They are containers for mix-type data. But your Nx1 table may just be a starting point for more vars.
To add a row at the beginning, do exactly the same thing you would do with a numeric vector: use vertcat.
>> t = table([1;2;3])
t =
3×1 table
Var1
____
1
2
3
>> t = [table(0); t]
t =
4×1 table
Var1
____
0
1
2
3

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by