简体   繁体   中英

Plotting continuous (not overlapping) timeseries data from different files on one graph in Matlab

I am writing Matlab code to open date files from a continuous air sampling instrument and could use help cleaning it up/formatting the plots correctly.

This is my code currently,

#importing data 
A101 = readtable("AE33_AE33-S10-01288_20220101.dat");
A102 = readtable("AE33_AE33-S10-01288_20220102.dat");
A103 = readtable("AE33_AE33-S10-01288_20220103.dat");
A104 = readtable("AE33_AE33-S10-01288_20220104.dat");

#removing empty cells
A101=A101(~any(ismissing(A101),2),:);
A102=A102(~any(ismissing(A102),2),:);
A103=A103(~any(ismissing(A103),2),:);
A104=A104(~any(ismissing(A104),2),:);

#times 
t1 = A101{:,2};
t2 = A102{:,2};
t3 = A103{:,2};
t4 = A104{:,2};
#BC data for each day 
b = A101{:,56};
c = A102{:,56};
d = A103{:,56};
e = A104{:,56};
#plotting 
plot(ts1, b, t2, c, t3, d, t4, e); 
title('BC concentration');
xlabel('Time (hours)');
ylabel('BC concentration (ng/m3)');
ylim([0,1600]);
legend({'1/01', '1/02', '1/03', '1/04'}) 

As of now, the days are all overlayed, but I need to have one continuous graph with an extended time series. The time is formatted in hr:min:sec in the second column of each table already & the instrument creates a new file for each day.

Additionally, if anyone could help me with a more concise way of importing the files & removing the blank cells I would appreciate it since I'll eventually be looking at months of data. I'm not particularly knowledgeable about coding/Matlab, so I'm sure some of these are easy fixes. Thanks!

If I am understanding you correctly, you want all of your data to be in one large column array instead of 4 smaller column arrays, right? If that is what you want then all you need to do is concatenate your data arrays.

For example, in your case, you would want:

AllData = [b;c;d;e];
AllTime = [t1;t2;t3;t4];

This would give you two column arrays that contain all the data points and all the time points respectively. One issue you may run into is if your time data restarts at 0 every day in which case you would need to add +24 hours to every time array in increasing magnitude.

For example:

AllTimeAdjusted = [t1; t2+24; t3+48; t4+72];

Note: You will not be able to preserve the legend entries as they are and may need to find another way to figure that out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM