Hovmoller Diagram: longitude (x axis), time (y axis), and z(temperature values)

조회 수: 77 (최근 30일)
I wuold like to extract temperature from a 3D matrix temp 609x881x372 (lonxlatxtime) and do an Hovmoller plot where I have time on the y-axis and longitude on the x-axis (see figure).
I created a logical matrix of 0 and 1 to identify where my coordinates meet my condition:
coord = (aa_lon>=-7 & aa_lon<=9 & aa_lat>=79 & aa_lat<=79.01);
coord is 609x881 logical but my matrix (temp) from which I want to extract the data is 609x881x372 double.
Hope my question is clear.
Please help me :)

채택된 답변

Mathieu NOE
Mathieu NOE 2023년 9월 13일
이동: Mathieu NOE 님. 2023년 9월 13일
hello again
I modified my code so it should work now on your data
as I understand we have here only 12 months of data , so my display assumes we have here only the first 12 months (1 year) of the entire time vector (which starts in Jan 1991) - you may need to correct this
also I changed a bit the tolerance on the latitude : aa_lat>=79 & aa_lat<=79+0.1
so we pick more data points of the temp matrix ; otherwise your diagram will have a very coarse display
result so far :
%% load data 609x881x12 (lonxlatxtime)
load lat.mat
load lon.mat
load time.mat
load temp.mat
%% convert time serial number into Y/M/D format
[y,mo,d,h,mi,s] = datevec(TT);% samplin time = 1 month (data is stored every 15th of the month)
%% spatial filtering
% coord = (aa_lon>=-7 & aa_lon<=9 & aa_lat>=79 & aa_lat<=79.01);
b = (aa_lat>=79 & aa_lat<=79+0.1); % play with tolerance (here 0.1) and see impact on how many points are selected
selected_lon = aa_lon(b);
ind_lon = (selected_lon>=-7 & selected_lon<=9);
final_lon = selected_lon(ind_lon);
%% main code
[m,n,p] = size(temp);
out = [];
for k = 1:p
tmp = temp(:,:,k);
selected_temp = tmp(b); % filtering for lat
selected_temp = selected_temp(ind_lon); % filtering for lon
% concatenation of the selected_temp data
out = [out; selected_temp']; % nb transpose of selected_temp to have data as row
% plot
% downsample Y tick spacing to display only years (tick position at january
% / 1st month of the year)
new_y = (1:12:p);
ylabel('Time (Years)');
% add horizontal line corresponding to january 15th (first data of the
% year)
hold on
for ci = 1:numel(new_y)
  댓글 수: 3
Carlotta Dentico
Carlotta Dentico 2023년 9월 20일
Hello! Yes, the code works perfectly :) Thank ou again

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Mathieu NOE
Mathieu NOE 2023년 9월 1일
maybe this ?
I created some dummy data to test my code
hope it helps
%% dummy data 609x881x372 (lonxlatxtime)
aa_lon = -45:0.1:60.9-45-0.1;
aa_lat = 0:0.1:88.1-0.1;
p = 10*12;% 10 years of monthly data = 120 time steps
for k = 1:p
data(:,:,k) = rand(609,881) + sin(0.1*k)*ones(609,881);
%% spatial filtering
% coord = (aa_lon>=-7 & aa_lon<=9 & aa_lat>=79 & aa_lat<=79.01);
% equivalent to :
a = (aa_lon>=-7 & aa_lon<=9);
b = (aa_lat>=79 & aa_lat<=79.01);
coord = logical(a'*b);
%% main code
[m,n,p] = size(data);
dt = 1; % put here the time increment or use a time vector if it exist
out = [];
% main loop
for k = 1:p
tmp = data(:,:,k);
tmp = tmp(coord); % spatial filtering of the data
time(k) = k*dt;
% time concatenation of the tmp data
out = [out; tmp']; % nb transpose of tmp to have data as row
% plot
x_plot = aa_lon(a);
ylabel('Time (months)');
  댓글 수: 4
Carlotta Dentico
Carlotta Dentico 2023년 9월 11일
Here the files :) I had to reduce the temperature file, that now is 609x881x12.
Mathieu NOE
Mathieu NOE 2023년 9월 13일
see my answer in the answer section below !

댓글을 달려면 로그인하십시오.


Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by