I have a problem with my script. I would like to extract pH data from the coast of Cameroon or the Gulf of Guinea. Can I have some ideas on what is bugging my script and a cor
Afficher commentaires plus anciens
clear all close all clc
disp('------------------------------------------------------') disp('Step 1 : Choix du fichier à traiter') [FileName,PathName,~] = uigetfile; disp('...... OK') disp('------------------------------------------------------')
disp('------------------------------------------------------') disp('Step 2 : Affichage des métadonnées netcdf') ncdisp([PathName,FileName]); disp('...... OK') disp('------------------------------------------------------')
disp('------------------------------------------------------') disp('Step 3 : Extraction des variables à Kribi (3°N; 9.5°E)') lon=ncread([PathName,FileName],'LONGITUDE'); % longitude lat=ncread([PathName,FileName],'LATITUDE'); % Latitude
[~,ilatK]=min(abs(lat-3.4)); % Indice latitude correspondant à Kribi [~,ilonK]=min(abs(lon-6.33)); % Indice longitude correspondant à Kribi
if (~isempty(ilatK)&&~isempty(ilonK)) pH=double(ncread([PathName,FileName],'PHPH',[ilonK,ilatK,1],[1 1 Inf],[1 1 1])); hsK=NaN(1,size(pH,2)); % Initialisation du vecteur de sorties des pH for i=1:size(pH,2) pHK(i)=pH(:,:,i); % Compilation de la série temporelle end
PH=ncread([PathName,FileName],'PHPH_QC',[ilonK,ilatK,1],[1 1 Inf],[1 1 1]);
PHK=NaN(1,size(PH,3)); % Initialisation du vecteur de sorties chl
for i=1:size(PH,3)
PHK(i)=chl(:,:,i); % Compilation de la série temporelle
end
end
disp('Step 4 : Time vector') t1=double(ncread([PathName,FileName],'TIME')); % Extraction du vecteur temps t=NaN(1,length(t1)); % Initialisation du vecteur de sorties du temps for i=1:length(t1) t(i)=datenum(1900,1,1,0,0,0)+(t1(i)/24); % Conversion en jours juliens end disp('...... OK')
hold on plot(t,pHK,'.-k','Linewidth',1,'Markersize',10) % Hauteur au large plot(t,PHK,'.-r','Linewidth',1,'Markersize',10) % Hauteur au déferlement hold off config_xdate(t,1,5,'pH',0) ylabel('pH (m)','fontweight','bold','fontsize',15) legend('SEA WATER','quality flag')
Réponse acceptée
Plus de réponses (1)
Peter Perkins
le 27 Nov 2023
Using datenums is no longer recomended.
t1=double(ncread([PathName,FileName],'TIME'));
...
t(i)=datenum(1900,1,1,0,0,0)+(t1(i)/24); % Conversion en jours juliens
...
plot(t,pHK,'.-k','Linewidth',1,'Markersize',10) % Hauteur au large
If the time in the file is really the number of hours since 1900, stored as a number, do this:
t1 = ncread([PathName,FileName],'TIME');
...
t(i) = datetime(1900,1,t1(i)); % Conversion en jours juliens
...
plot(t,pHK,'.-k','Linewidth',1,'Markersize',10) % Hauteur au large
Catégories
En savoir plus sur Animation dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
