필터 지우기
필터 지우기

Copy table's certain data into another table with corresponding variable names

조회 수: 103 (최근 30일)
Let's say I have a table with 10 rows and 10 columns. I'd like to copy 5 cols and 10 rows of the table into another one with their variable names. Is there a way to do that?
Thank you.

채택된 답변

Mohammad Abouali
Mohammad Abouali 2014년 10월 22일
Lets say you want move column Age from table1 to table2
table2.Age=table1.Age
Or if you want to move column 5 to 8 of table1 to table2 do this:
for c=5:8
table2.(T.Properties.VariableNames{c})=table1.(T.Properties.VariableNames{c});
end
  댓글 수: 2
Ege
Ege 2014년 10월 23일
When I try this on a sample table I get "Error using table/subsrefDot (line 48) Index exceeds matrix dimensions.
Error in table/subsref (line 62) [varargout{1:nargout}] = subsrefDot(t,s);" error
Mohammad Abouali
Mohammad Abouali 2014년 10월 23일
편집: Mohammad Abouali 2014년 10월 23일
Do your two tables have the same number of rows?
By the way, I have assumed that both table2 and table1 are already defined.

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

추가 답변 (1개)

Guillaume
Guillaume 2014년 10월 22일
편집: Guillaume 2014년 10월 22일
Just use normal indexing to get your new table:
demotable = cell2table(num2cell(randi(100, 10, 10)), ...
'VariableNames', ...
arrayfun(@(n) sprintf('Name_%d', n), 1:10, 'uni', 0))
newtable = demotable(:, 3:7)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by