append rows of a table

조회 수: 65 (최근 30일)
Robert
Robert 2021년 7월 27일
댓글: Peter Perkins 2021년 7월 28일
So i would like to take two tables lets say T1 and T2
I want to take a single line if T2 and append it to the end of T1.
I found this could as an example. It works just fine except it appends the enitre table. I want to just append a single row from T2 and tack it on to the end of T1.
Anyone have any ideas?
T2 = readtable('morePatients.csv');
Tnew = [T;T2];
size(Tnew)
  댓글 수: 5
Walter Roberson
Walter Roberson 2021년 7월 27일
Tnew = [T;T2(1,:)];
maybe? This would only work if the variable names match (though iirc if the names match but are in a different order then the entries will be matched by variable name.)
Peter Perkins
Peter Perkins 2021년 7월 28일
Correct. If the two sets of var names differ only by permutation, vertcat matches them up. If the two sets are more different than that, that's a whole 'nuther question.

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

답변 (1개)

Walter Roberson
Walter Roberson 2021년 7월 27일
The general solution is to vertcat or [;] a cell array that has the same number of columns that as the table has variables. This will work even if the table contains multiple data types. Values being appended will have their type converted if necessary.
You might need to use table2cell if your table has multiple data types.
Or if the variable names match you can just vertcat T2(1,:)

카테고리

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

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by