How to convert XLim day data to monthly?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi there, as you can see below I've got monthly data plotted by it is displayed along the x-axis as days. How do you change it so it is not 1:366 (days) but 1:12 (months). Thank
Here is my script for these plots:
allt=[data2009.t data2010.t data2011.t data2012.t ...
data2013.t data2014.t data2015.t data2016.t];
allT=[data2009.T data2010.T data2011.T data2012.T ...
data2013.T data2014.T data2015.T data2016.T];
allS=[data2009.S data2010.S data2011.S data2012.S data2013.S data2014.S data2015.S data2016.S];
allTu=[data2009.Tu data2010.Tu data2011.Tu data2012.Tu data2013.Tu data2014.Tu data2015.Tu data2016.Tu];
for I=1:12
monthstart(I) = day(datetime(2009,I,1),'dayofyear');
end
monthstart (13) = 366;
for I=1:12
tmpT = allT(find (allt>monthstart(I) &allt<monthstart(I+1)));
tmpT(isnan(tmpT))=[];
meanT(I)=mean(tmpT);
stdT(I)=std(tmpT);
end
for I=1:12
tmpT = data2016.T(find (data2016.t>monthstart(I) & data2016.t<monthstart(I+1)));
tmpT(isnan(tmpT))=[];
meanT2016(I)=mean(tmpT);
stdT2016(I)=std(tmpT);
end
for I=1:12
tmpS = allS(find (allt>monthstart(I) &allt<monthstart(I+1)));
tmpS(isnan(tmpS))=[];
meanS(I)=mean(tmpS);
stdS(I)=std(tmpS);
end
for I=1:12
tmpS = data2016.S(find (data2016.t>monthstart(I) & data2016.t<monthstart(I+1)));
tmpS(isnan(tmpS))=[];
meanS2016(I)=mean(tmpS);
stdS2016(I)=std(tmpS);
end
for I=1:12
tmpTu = allTu(find (allt>monthstart(I) &allt<monthstart(I+1)));
tmpTu(isnan(tmpTu))=[];
meanTu(I)=mean(tmpTu);
stdTu(I)=std(tmpTu);
end
for I=1:12
tmpTu = data2016.Tu(find (data2016.t>monthstart(I) & data2016.t<monthstart(I+1)));
tmpTu(isnan(tmpTu))=[];
meanTu2016(I)=mean(tmpTu);
stdTu2016(I)=std(tmpTu);
end
figure(2)
%clf
subplot (3,1,1)
plot(monthstart(1:12),meanT,'b-', 'LineWidth', 2)
hold on
plot(monthstart(1:12),meanT2016,'r-', 'LineWidth', 2)
plot(monthstart(1:12),meanT+stdT,'b--')
plot(monthstart(1:12),meanT-stdT,'b--')
plot(monthstart(1:12),meanT2016+stdT2016,'r--')
plot(monthstart(1:12),meanT2016-stdT,'r--')
xlabel('Day Of Year')
ylabel ('SST (^oC)')
title ('L4 monthly Mean Sea Surface Temperature')
set(gca,'XLim',[1 366])
legend('2009-2015','2016')
subplot (3,1,2)
plot(monthstart(1:12),meanS,'b-', 'LineWidth', 2)
hold on
plot(monthstart(1:12),meanS2016,'r-', 'LineWidth', 2)
plot(monthstart(1:12),meanS+stdS,'b--')
plot(monthstart(1:12),meanS-stdS,'b--')
plot(monthstart(1:12),meanS2016+stdS2016,'r--')
plot(monthstart(1:12),meanS2016-stdS,'r--')
xlabel('Day Of Year')
ylabel ('SSS (ppt)')
title ('L4 monthly Mean Sea Surface Salinity')
set(gca,'XLim',[1 366])
legend('2009-2015','2016')
subplot (3,1,3)
plot(monthstart(1:12),meanTu,'b-', 'LineWidth', 2)
hold on
plot(monthstart(1:12),meanTu2016,'r-', 'LineWidth', 2)
plot(monthstart(1:12),meanTu+stdTu,'b--')
plot(monthstart(1:12),meanTu-stdTu,'b--')
plot(monthstart(1:12),meanTu2016+stdTu2016,'r--')
plot(monthstart(1:12),meanTu2016-stdTu,'r--')
xlabel('Day Of Year')
ylabel ('SSTu')
title ('L4 monthly Mean Sea Surface Turbility')
set(gca,'XLim',[1 366])
legend('2009-2015','2016')
0 commentaires
Réponses (1)
Star Strider
le 10 Oct 2019
Since you’re using datetime arrays, using the xtickformat function and specifically using 'MM' or 'MMM' as described in the datefmt section of the documentation would likely do what you want.
0 commentaires
Voir également
Catégories
En savoir plus sur Formatting and Annotation dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!