Interpolate both dataset on a same grid

2 次查看(过去 30 天)
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 个评论
Sophia
Sophia 2018-3-19
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 2018-3-20
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...

请先登录,再进行评论。

回答(2 个)

Jan
Jan 2018-3-20
编辑:Jan 2018-3-20
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 个评论
Sophia
Sophia 2018-3-20
编辑:Sophia 2018-3-20
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?

请先登录,再进行评论。


Sophia
Sophia 2018-3-19
编辑:John D'Errico 2018-3-20
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 个评论
Stephen23
Stephen23 2018-3-20
编辑:Stephen23 2018-3-20
"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 2018-3-20
thanks guys it helped, the Matlab Central send me the mail assuring none of my information has been compromised. Thanks for the flag.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by