How to do matrix regridding in matlab
Show older comments
Hello, I am trying to use matlab to regrid a dataset. The original dataset is 128x193x12 (longitude x latitude x time) and I want to regrid it to a 180x193x12 matrix. I have the latitude of the original dataset as a 64x1 single (Dust_Data_lat), the longitude as a 128x1 single (Dust_Data_lon). For the 'final' grid (180x193x12), I have a latitude matrix 180x193 (constant columns, DUST_IN_lat) and a longitude matrix 180x193 (constant rows, DUST_IN_lon). I think the function griddata is best for this as the grid is irregular. If I try however, it complains about 'Z', which I don't know, see here for the first time dimension of the data:
a=Dust_LGM(:,:,1);
data_regridded = griddata(Dust_Data_lon,Dust_Data_lat,a,DUST_IN_lon,DUST_IN_lat);
The error I get is:
Error using griddata (line 109)
The lengths of X and Y must match the size of Z.
Would you know where the mistake is?
2 Comments
Matt J
on 4 Apr 2018
You should close your previous question by accept-clicking Jos' answer, since it appears you were happy with that answer. This will increase the likelihood of responses to future questions.
Anne
on 5 Apr 2018
Answers (1)
In griddata(x,y,z,xq,yq) the input arrays x,y,z must have the same number of elements. You have 128*193=24704 elements in a. You must therefore have 24704 corresponding elements in both Dust_Data_lon and Dust_Data_lat.
15 Comments
Anne
on 9 Apr 2018
Matt J
on 9 Apr 2018
You said initially that your data was scattered, not gridded. If that is still true, then it's hard to see how meshgrid would make sense.
Anne
on 9 Apr 2018
Anne
on 9 Apr 2018
"Gridded" means that the set of all (x,y) coordinates corresponding to the different input z data points can be generated using meshgrid() or ndgrid(). In other words, they lie at the nodes of some rectangular lattice. If this is not the case, the data is said to be "scattered".
Anne
on 10 Apr 2018
Matt J
on 10 Apr 2018
I suggest that you attach a .mat file containing Dust_Data_lon,Dust_Data_lat,Dust_LGM,DUST_IN_lon,DUST_IN_lat. That way, we can all play with it.
Anne
on 11 Apr 2018
Anne
on 16 Apr 2018
Matt J
on 16 Apr 2018
You cannot (and should not) remove it. If my response leads to the resolution of your issue, you should also Accept-click it.
Yoichi
on 21 Sep 2018
It looks like your range of longitudes cross the prime meridian (0 longitude). You may want to make all longitudes positive (for example adding 360 to the longitudes less than zero) before moving forward.
Anne
on 22 Sep 2018
xinyu dong
on 19 Jul 2019
Hey Anne. I am struggling how to regrid with lon and lat right now. Do you have any recommandation? Thank you very much!
Categories
Find more on External Language Interfaces in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!