How to combine multiple time spans in Matlab?

3 ビュー (過去 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 Center および File ExchangeTables についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by