Resizing a small matrix to a larger one

I have a matrix of some satellite data (size 446x307) and a matrix of some interpolated in-situ data (size must be a square grid i.e. NxN .. so for example I could make it 307x307). They cover the same area (I have latitude and longitude matrices for both the satellite and in-situ data as well which are 446x307 and NxN), but they are different sizes. How do I either expand the in-situ to a 446x307 matrix, or squash the satellite data into a 307x307, without losing the data? I'm needing to do this so that I can then compare the two by the individual pixels for error analysis.
I think it may be something to do with interpolating the in-situ to a larger matrix, but I'm not sure.

2 commentaires

Guillaume
Guillaume le 20 Août 2014
Is it matrices or images you want to resize?
Roseanne
Roseanne le 20 Août 2014
It is the matrices I am trying to resize. So I have latitude,longitude and a data product (which I have got from satellite data - 446x307), and then the latitude, longitude and the same data product from in-situ data - 307x307. It's just resizing would be good as then I could compare specific points (specified by latitude and longitude) for the data product.

Connectez-vous pour commenter.

Réponses (2)

Adam
Adam le 20 Août 2014
griddedInterpolant
would do the job of regridding. If you don't want to lose data though you will, as you say, need to expand the smaller rather than squash the larger. That will introduce interpolated data along one dimension, but that is unavoidable I think if you are changing the x/y size ratio.

4 commentaires

Roseanne
Roseanne le 20 Août 2014
I'm not sure how to use this function. I've tried reading about it, but I don't know how to apply it to my data? k_insitu=griddedInterpolant(lon_sat,lat_sat,k_sat,lon_insitu,lat_insitu) doesn't seem to be working for me.
Try
interp2
instead maybe. I think it uses griddedInterpolant in its implementation but is a little more user-friendly to use. Basically just use meshgrid to create your old grid and your new grid and pass these, together with your values on the old grid to the interp2 function.
Roseanne
Roseanne le 20 Août 2014
Thanks for your help so far! interp2 doesn't allow NaNs (which I have when it includes land in my area), and if I were to set these to another value such as 0, it would include this value in the interpolation?
Adam
Adam le 20 Août 2014
interp2 seems to work fine with Nans for me with data as doubles. Well, when i say fine I mean it handles them. It widens them out more than I would want, but it doesn't crash or anything like that.

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 20 Août 2014

0 votes

Simply use imresize(). It's a lot easier than griddedInterpolant. Not sure how imresize() handles nans though - you'd have to check. You can convert nans to zeros if you want to or need to before calling imresize().

2 commentaires

Adam
Adam le 20 Août 2014
I keep forgetting there is an imresize function in the Image Processing Toolbox.
It does handle nans, but seems to expand them more than perhaps you might want.
Roseanne
Roseanne le 20 Août 2014
Sadly (as you saw on my question about masking coastlines), I do not have the image processing toolbox. Do you know of any similar codes for either curve fitting or statistics toolboxes?

Connectez-vous pour commenter.

Question posée :

le 20 Août 2014

Commenté :

le 20 Août 2014

Community Treasure Hunt

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

Start Hunting!

Translated by