Copying colums from table to a new table

조회 수: 39 (최근 30일)
Mat P
Mat P 2020년 6월 30일
댓글: Mat P 2020년 6월 30일
I am struggling with a quite simple issue:
I have multiple different sized tables, and i would like to copy last columns of every (time)table to a new table that i have not defined. That doesn't work because the length are different in every column. The excessive values in some columns could be set as "Nan"s or just removed. IS there a easy way to do this? The only method that comes to my mind is to create an excel .csv file with zeros, but my tables are very large.

채택된 답변

Adam Danz
Adam Danz 2020년 6월 30일
Follow the demo; see inline comments for details.
% Create 3 timetables of different heights
dt = datetime(2000,1,1,0,0,0) + minutes(0:30:5000)';
TT1 = timetable(dt(1:100),rand(100,1));
TT2 = timetable(dt(1:85),rand(85,1));
TT3 = timetable(dt, rand(size(dt)));
% List all timetables in a cell array named "allTT"
allTT = {TT1, TT2, TT3};
% Get heights of all timetables
heights = cellfun(@height, allTT);
% Loop through each timetable and move the last column into
% the table T; use NaNs as fillers.
T = array2table(nan(max(heights), numel(allTT))); % You may want to name your variables here.
for i = 1:numel(allTT)
T{1:heights(i),i} = allTT{i}{:,end};
end
  댓글 수: 1
Mat P
Mat P 2020년 6월 30일
Thank you! I think I manage to do just what I want with this

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

추가 답변 (1개)

SC
SC 2020년 6월 30일
Hey, This link might help you:
go to 'Table with Multiple Data Types' in the above link
  댓글 수: 1
Mat P
Mat P 2020년 6월 30일
Thank you for the answer. I don't think that i can use that. My goal is to copy these columns to new timetable, but i can't do that because the lengths are different. And that doesn't allow me to add extra zeros to the end of smaller tables, to make them all equal sized

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

카테고리

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