Hello, I made a code to create time series et climatological graphics but my figure remain empty, I've noticed that I have some of my matrix how are filled with "NaN" but i don't really know where the problem come from, or at least how to fix it… Here is the code : (titles are in french sorry for that)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CREATION DES SERIES MENSUELLES DES PIXELS.%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Chargement des données brutes.
%-------------------------------
T = Morocco0218% parse dates
[y,m,d] = datevec(T.acq_date); Tdate = table(y,m,d,'VariableName',{'year','month','day'}); % Create new table
CAD_FEUX = [Tdate,T(:,{'latitude','longitude'})]; MAT=CAD_FEUX;MAT_YEAR=CAD_FEUX(:,1);MAT_MOIS=CAD_FEUX(:,2);MAT_JOURS=CAD_FEUX(:,3);% Série mensuelle.
%-----------------
SM_TPS1(2002,2018);load('time.mat')u=0;for j=2002:2018 u=u+1; BLOC_1=find(isequal((MAT_YEAR(:,1)),j)); BLOC_ANNEE_T=MAT(BLOC_1,:);k=0;for t=1:12 k=k+1; x1=find(isequal((MAT_MOIS(BLOC_1,1)),t)); if numel(x1)==0; MOY_J=NaN; else MOY_J1=numel(BLOC_ANNEE_T(x1,1)); MOY_J=MOY_J1; end MOY_T(k,1)=MOY_J; endMatrice(:,u)=MOY_T;endr1=numel(Matrice(1,:)); % Stockage des valeurs de "Valeur" dans une matrice colonne.
o1=0;for m1=1:r1 for m11=1:numel(Matrice(:,1)); o1=o1+1; values11=cat(1,Matrice(m11,m1)); PIX_MENS(o1,:)=values11; endendMAT_PIX=cat(2,MAT_TPS,PIX_MENS);clear u r1 o1 x1 m1 m11 BLOC_1 values11 Matrice k t MOY_T MOY_J j BLOC_ANNEE_T%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Série climatologique globale.%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c=0; for j=1:12; c=c+1; x=find(MAT_PIX(:,2)==j); MOY_MAT=nanmean(MAT_PIX(x,3)); STD_MAT=nanstd(MAT_PIX(x,3)); CLIMATO_PIX(c,1)=MOY_MAT; DISP_PIX(c,1)=STD_MAT; end clear x j csave MAT_PIX_SA.mat MAT_PIX CLIMATO_PIX DISP_PIX%%%%%%%%
%FIGURE%
%%%%%%%%%SERIE CLIMATO
%--------------
scrsz=get(0,'ScreenSize');figure1 = figure('Position',[1 1 scrsz(3)/2.2 scrsz(4)/2.4]); %[ left bottom largeur hauteur]
TPS2=1:length(CLIMATO_PIX(:,1));errorbar(TPS2,CLIMATO_PIX,DISP_PIX,'o--')xlim([0 13])set(gca,'xtick',1:1:12,'xtickLabel',{'J';'F';'M';'A';'M';'J';'J';'A';'S';'O';'N';'D'},'fontweight','bold');xlabel('Month','fontweight','bold')ylabel('PIXELS','fontweight','bold')grid on%SERIE MENSUELLE
%---------------
scrsz=get(0,'ScreenSize');figure5 = figure('Position',[1 1 scrsz(3)/2.2 scrsz(4)/2.4]); %[ left bottom largeur hauteur]TPS=1:length(MAT_PIX(:,1));plot(TPS,MAT_PIX(:,3),'o--')fin=numel(MAT_PIX(:,1));xlim([0 fin+10])set(gca,'xtick',1:24:fin,'xtickLabel',{'2002';'2004';'2006';'2008';'2010';'2012';'2014';'2016';'2018'},'fontweight','bold');xlabel('Year','fontweight','bold')ylabel('PIXELS','fontweight','bold')grid on
PIX_MENS, CLIMATO_PIX and DISP_PIX are empty as well as MAT_PIX where only the third variable of the table is empty. They are all needed to plot to graph but I have no clue about how to fix the problem…
If anyone can help me…
Have a good day,
Thomas V.
Best Answer