I have an 81033×4 table in which the first column holds the timestamp for each date and time (format mm/dd/yy HH:mm), the second column is the datenum for each timestamp, and the other 2 columns are the recordings for each stamp
- How do I extract sets of data from my table depending on the timestamp? I'd like to extract the rows for each year of data (2010:2020)
- How do I plot timestamp vs data (Acc_Ext, Acc_Int) for each year?
The data looks like this:
(disregard the x34, I can create one that with only the first 4 columns)
An initial idea I had is:
[num,text] = xlsread('NODE2.WDH.csv', 'A1:D81034'); datenumColumn = num(:,1); rowtotal = length(datenumColumn); % Find datenum value for start of each year
for n = 2010:2021 Y(n) = datenum(n,1,1); end ind = find(Y > 0); A = [ind',Y(ind)']; B = A(:,2); % B is the array containing all the date strings for the start of each year
data_2010 = num((B(1)<=datenumColumn)&(datenumColumn<=B(2)), :); data_2011 = num((B(2)<=datenumColumn)&(datenumColumn<=B(3)), :); data_2012 = num((B(3)<=datenumColumn)&(datenumColumn<=B(4)), :); data_2013 = num((B(4)<=datenumColumn)&(datenumColumn<=B(5)), :); data_2014 = num((B(5)<=datenumColumn)&(datenumColumn<=B(6)), :); data_2015 = num((B(6)<=datenumColumn)&(datenumColumn<=B(7)), :); data_2016 = num((B(7)<=datenumColumn)&(datenumColumn<=B(8)), :); data_2017 = num((B(8)<=datenumColumn)&(datenumColumn<=B(9)), :); data_2018 = num((B(9)<=datenumColumn)&(datenumColumn<=B(10)), :); data_2019 = num((B(10)<=datenumColumn)&(datenumColumn<=B(11)), :); data_2020 = num((B(11)<=datenumColumn)&(datenumColumn<=B(12)), :); % Create Figure for all data from Node
t = tiledlayout(3,4,'TileSpacing','Compact','Padding','Compact'); % Tiles
for i = 0:12 nexttile() x = data_201i(:,1); y1 = data_201i(:,2); y2 = data_201i(:,3); plot(x,y1,'k-'); title('2020') hold on; plot(x,y2,'b-'); datetick('x','mmm','keepticks') % This function read the time intervals and displays them in the x-axis
tstart = data_201i(1,1); tend = data_201i(size(data_201i,1),1); xlim([tstart tend]) xlabel('Month') end
However, I can't get the data to be plotted for each iteration.
Best Answer