Interpolate both dataset on a same grid

5 visualizaciones (últimos 30 días)
Sophia
Sophia el 19 de Mzo. de 2018
Editada: Sophia el 20 de Mzo. de 2018
Hi, i have the two different datasets (PFA the excel file) as following
Dataset A size (119*177) with each lat and long file of same size
Dataset B size (145*73) with long size of (145*1) and lat size of (73*1)
The steps according to my understanding are-
  • Make a lat, long file for dataset B of size (145*73) - question how to do that?
  • Interpolate the dataset A to the size of Dataset B, which i am guessing using interp2
  5 comentarios
Sophia
Sophia el 19 de Mzo. de 2018
Hi, The reason why i attached the file was to give a detailed idea about the matrix sizes.
The simplest way to define my problem is i have the results from two different datasets which are on two different lat/long grids. I want to interpolate them on to a common grid and find the normalized two-dimensional cross correlation.
I tried this for my first question ( Make a lat, long file for dataset B of size (145*73) - question how to do that?), and it seem to work but not sure until i have the final result
%%change the long and lat from 1D to 2D
[mm,nn] = size(skw_16); %skw_16 is of the size 119*117
%long is 1*145, lat is 1*73 %change them to 145*73
nlong = zeros(mm,nn); nlat = zeros(mm,nn);
for i = 1:mm
nlong(i,:) = lat(:)'; %nlong(i,:) = long(longstart:longend)';
end
for j = 1:nn
nlat(:,j) = long(:)'; %nlat(i,:) = lat(latstart:latend)';
end
%The result %nlong 145*73, nlat 145*73
Now i am onto my second question- *Interpolate the dataset A to the size of Dataset B, which i am guessing using interp2*
skw_mtn_ncep = interp2(long,lat,skw_ids_2016,nlong,nlat);
%long 119*177, lat 119*177, skw_ids_2016 119*177
or should i interpolate the 145*73 onto 119*73?
Jan
Jan el 20 de Mzo. de 2018
An abbreviation for the first part:
nlong = repmat(lat, mm, 1);
nlat = repmat(long(:), 1, nn);
But you do not need to create matrices with the grid coordinates, because interp2 accepts vectors directly.
See my answer...

Iniciar sesión para comentar.

Respuestas (2)

Jan
Jan el 20 de Mzo. de 2018
Editada: Jan el 20 de Mzo. de 2018
I assume that this helps:
B = rand(145, 73);
A = rand(119, 177);
y = linspace(1, 145, 199);
x = linspace(1, 73, 177);
BB = interp2(1:73, (1:145).', B, x, y.');
Now BB is the linear interpolation of B with the same size as A.
Note: I still find the order of the coordinates for interp2 counter-intuitive:
Vq = interp2(V,Xq,Yq) assumes X=1:N and Y=1:M where [M,N]=SIZE(V)
I'd expect the 1st input to be correlated to size(V, 1) and the 2nd to size(V,2), but MathWorks decided to swap the order. This is at least consistent with e.g. gradient.
  1 comentario
Sophia
Sophia el 20 de Mzo. de 2018
Editada: Sophia el 20 de Mzo. de 2018
Okie, here comes the part why i attached the excel file. From my understanding of your code A and B are two datasets. But x and y, i am not sure what they are representing here. In my case i have lat and long for each A and B. And the max and min lat/long values in both case are different.
I am not sure if i am explaining my question well enough or not. let's assume for example you have the data for United States at a grid of 25km*25km. And another dataset in which the data might be extended upto Canada but still has the data for United States, at a grid of 2.5 degree.
The idea is to plot them on a common grid, and find the 2D cross-correlation between them for just the common areas.
so in that case-
y = linspace(1, 145, 199);
x = linspace(1, 73, 177);
I am wondering, if its the right way?

Iniciar sesión para comentar.


Sophia
Sophia el 19 de Mzo. de 2018
Editada: John D'Errico el 20 de Mzo. de 2018
I just received this e-mail. I am worried how come MATHWORKS can share my personal email with any random person. The e-mail is as following-
This message was sent to you by this author via your author page on MATLAB Central.
Hello, I read your question in Matlab Central and would like to offer you my instant 1-to-1 programming service. An affordable, quick and tailored matlab-programming service to your needs. Check it out at: www.bit.ly/******** Thank you*
  6 comentarios
Stephen23
Stephen23 el 20 de Mzo. de 2018
Editada: Stephen23 el 20 de Mzo. de 2018
"Offering a programming service in a Matlab forum is not completely off-topic"
However it a clear violation of the terms of use for this forum:
1.e "You agree ... nor to use the communication systems provided by the Site (e.g., comments) for any commercial solicitation purposes."
2.a.iv "You may not use the Site to sell or market your products or services to others."
Sophia
Sophia el 20 de Mzo. de 2018
thanks guys it helped, the Matlab Central send me the mail assuring none of my information has been compromised. Thanks for the flag.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Preprocessing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by