How to combine multiple time spans in Matlab?

조회 수: 1 (최근 30일)
Chamath Vithanawasam
Chamath Vithanawasam 2018년 7월 25일
댓글: Peter Perkins 2018년 8월 3일
I have data from multiple .txt files, each displaying temperature at different times throughout the day. Each .txt file is for one day. I want to combine all these dates and their respective recorded temperatures into one table, so that I can plot for a very large time duration, i.e. 3 months, etc.
Suppose I collect the data for 3 days.
Day1 = 'SI010218.log';
Day2 = 'SI020218.log';
Day3 = 'SI030218.log';
opts = detectImportOptions(Day1);
opts = setvartype(opts,1,'datetime');
opts = setvaropts(opts,1,'InputFormat','dd.MM.uuuu HH:mm:ss');
table1 = readtable(Day1,opts);
opts = detectImportOptions(Day2);
opts = setvartype(opts,1,'datetime');
opts = setvaropts(opts,1,'InputFormat','dd.MM.uuuu HH:mm:ss');
table2 = readtable(Day2,opts);
table2([1417],:) = [];
opts = detectImportOptions(Day3);
opts = setvartype(opts,1,'datetime');
opts = setvaropts(opts,1,'InputFormat','dd.MM.uuuu HH:mm:ss');
table3 = readtable(Day3,opts);
This creates 3 tables holding all the data from each of the .txt files. Column 1 holds the date and time, and column 8 holds the desired y-axis values. How do I add all the time values from column 1 into a separate table along with the y axis value placed in column 8? I am attaching the .txt files as well.

채택된 답변

Harsh
Harsh 2018년 7월 27일
Not sure what your end goal is but if you'd like to bring the variables of the table together, you can try the following in addition to your current code:
>> table1.Properties.VariableNames{'TimeStamp'} = 'TimeStamp_1';
>> table2.Properties.VariableNames{'TimeStamp'} = 'TimeStamp_2';
>> table3.Properties.VariableNames{'TimeStamp'} = 'TimeStamp_3';
>> tt = [table1(:,1), table2(:,1), table3(:,1)]; %variables next to each other
If you would like to stack data from multiple variables into single variable:
>> st = stack(tt,1:3);
This can be done with column 8 data (y-axis) as well and I suppose you could then plot the data.
  댓글 수: 1
Peter Perkins
Peter Perkins 2018년 8월 3일
Harsh's suggestion does a horizontal concatenation. I would have guess you'd have wanted a vertical concatenation. That's just vertcat, i.e.
t = [table1; table2; table3];
If that's where you want to end up, you probably should be using timetables, not tables.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by