How to combine multiple time spans in Matlab?

1 次查看(过去 30 天)
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