MATLAB: Plotting of 15 years data on same graph.

data plotdatenumyear over year

I have data of 15 years as i have attached here, which has the format as: Date, time, Pressure data, Temperature Data.
I want to plot the temperature dataset year over year, lets say on x-axis january-december is labeled i want to plot each year data (just Temperature) with different colored plots on the same graph.
Thanks in advance

Best Answer

Try something like this:
fid = fopen('Mod21_All_Inclusive_Data_Nov2019.txt');
Mod = textscan(fid,'%s %s %n %n');
fclose(fid); % Close the file
Temp = Mod{3};
DMY =cellstr(Mod{1});
HM = cellstr(Mod{2});
DMYHM = datetime(DMY,'InputFormat','MM/dd/yy') + duration(HM,'InputFormat','hh:mm');
Y = year(DMYHM);
yrs = unique(Y);
x_axis = day(DMYHM,'dayofyear') + (hour(DMYHM) + (minute(DMYHM)/60))/24;
fig = figure;
hold on
for t = 1:numel(yrs)
yr = yrs(t);
idx = yr == Y;
plot(x_axis(idx),Temp(idx));
end
XTicks = nan(1,12);
XTickLabels = cell(12,1);
for n = 1:12
dt = datetime(2019,n,01);
XTicks(n) = day(dt,'dayofyear');
XTickLabels(n) = month(dt,'name');
end
ax = gca;
ax.XTick = XTicks;
ax.XTickLabel = XTickLabels;
fclose(fid);