Problem with "datetick" on plot

11 次查看(过去 30 天)
ProjectVOC
ProjectVOC 2013-11-13
评论: ProjectVOC 2013-11-13
Hello,
I have a problem with the command datetick. I try to plot a figure with the date in month on x Axis (just each month on x axis). Instead of that, the result is just a vector on x from 1 to the end of the vector y. Here is my code, it will be easier to understand if you run it ( I apologize for my English, I'm not fluent ). The problem is at the end of the code. Thank you for your time
% Routine de départ
close all
clear all
clc
load Projet_Thematique_data.mat
complete_data(complete_data==-999)=nan;
complete_data(any(isnan(complete_data(:,1)),2),:)=[];
date=datevec(complete_data(:,1) + 693960);
% Tri mais
IdxCult=find(strcmp(complete_titre,'Cult'));
Idx=find(complete_data(:,IdxCult)==1);
% Tri flux
fluxmais=find(strncmp(complete_titre,'Flux',4));
fluxmais=fluxmais(1,1:12);
fluxmaisvoc=fluxmais;
fluxmaisvoc(2)=[];
% Groupe
Group=ones(length(Idx),1);
% Calcul moyenne/ecart-type flux
for i=1:length(fluxmaisvoc);
[moyenne(i),std(i),nb(i)]=grpstats(complete_data(Idx,fluxmaisvoc(i)),Group,
{'mean','std','numel'});
end
% Display !!!Ajouter erreur standard de la moyenne!!!
figure(1)
hold on
bar(moyenne);
errorbar(moyenne,std);
set(gca,'XTick',1:1:length(moyenne),'XTickLabel',
{'M33','M45','M59','M69','M71','M83','M137','M73','M79','M61','M93'});
ylabel('Moyenne');
hold off
% Dynamique annuelle
for i=1:length(fluxmais);
k=0;
for j=11:length(Idx)-10;
k=k+1;
mobilemean(k,i)=nansum(complete_data(Idx(j-10:j+10),fluxmais(i)))/sum(isfinite(complete_data(Idx(j-10:j+10),fluxmais(i))));
end
figure(i+1)
plot(mobilemean(:,i));
xlabel('Mois');
datetick('complete_data(Idx(11:end-10),1)','3');
end
clear i
clear j
clear k

回答(1 个)

Sean de Wolski
Sean de Wolski 2013-11-13
The first input to datetick() should be the axis to plot on on.
For example:
x = floor(now)-200:floor(now)+200; %dates 200 days before and after now
plot(x,rand(size(x))) %some random plot
datetick('x','mmmyy') %datetick the x-axis with the format mmmyy
And for more info/examples
doc datetick

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by