Filter löschen
Filter löschen

How to combine multiple time spans in Matlab?

3 Ansichten (letzte 30 Tage)
Chamath Vithanawasam
Chamath Vithanawasam am 25 Jul. 2018
Kommentiert: Peter Perkins am 3 Aug. 2018
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.

Akzeptierte Antwort

Harsh
Harsh am 27 Jul. 2018
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 Kommentar
Peter Perkins
Peter Perkins am 3 Aug. 2018
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by