Using scatteredinterpolant instead of griidedinterpolant

6 Ansichten (letzte 30 Tage)
Hitesh Bugata
Hitesh Bugata am 27 Sep. 2020
Beantwortet: Matt J am 27 Sep. 2020
I have a spatial data of fine resolution in gridded format of a CSV file. I want to use griddedinterpolant function and upscale into a little coarser format. But when I created a meshgrid with the source data lat-lon points, it has become unresponsive stating the generated grid is 28GB memory and MATLAB cannot process such huge data. So is the case when I used interp2. When I tried scatteredinterpolation function, it worked like a charm. Output files have been generated with more or less satisfying results. My question is what to do when we cannot use griddedinterpolant for gridded data of very fine spatial resolution? Is scatteredinterpolant safe to use as an alternative to griddedinterpolant in such cases?
Thank you in advance.
  3 Kommentare
Hitesh Bugata
Hitesh Bugata am 27 Sep. 2020
I have understood the mistake from your explanation of space occupied by using mesh grid again and again. I've realized the mistake I'm making.
Hitesh Bugata
Hitesh Bugata am 27 Sep. 2020
Can you put the space occupied comment as another answer so that I can accept it as an answer?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt J
Matt J am 27 Sep. 2020
It looks like the latitude and longitude data in your CSV files are already meshgridded. By meshgridding them an additional time, you have created an explosion of unnecessary duplicate latitude and longitude values. See how the memory consumption grows exponentially in the following simplified illustration of what you've done:
>> x=1:30;y=2:31;
>> [X,Y]=meshgrid(x,y);
>> [XX,YY]=meshgrid(X,Y);
>> whos x y X Y XX YY
Name Size Bytes Class Attributes
X 30x30 7200 double
XX 900x900 6480000 double
Y 30x30 7200 double
YY 900x900 6480000 double
x 1x30 240 double
y 1x30 240 double

Weitere Antworten (2)

Image Analyst
Image Analyst am 27 Sep. 2020
Why not simply use imresize()?
  4 Kommentare
Image Analyst
Image Analyst am 27 Sep. 2020
You said " My question is what to do when we cannot use griddedinterpolant for gridded data of very fine spatial resolution?" so do you have gridded data (a 2-D matrix) or not? I always use scatteredInterpolant() because it's the more general of the functions and will work in all cases. Why do you say you can't use griddedIterpolant for very fine spatial resolution? What is en example of that situation?
Hitesh Bugata
Hitesh Bugata am 27 Sep. 2020
I have a fine resolution data in .CSV format in the format as atatched in the image. To use griddedinterpolant or interp2, a meshgrid or ndgrid needs to be created using lat, lon values. When I did that step, command window shows " Requested 61890x61890 (28.5GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive.". I need data at coarser resolution for a work.

Melden Sie sich an, um zu kommentieren.


Matt J
Matt J am 27 Sep. 2020
Bearbeitet: Matt J am 27 Sep. 2020
But when I created a meshgrid with the source data lat-lon points.
You should not create a meshgrid, since it consumes unnecessary memory. You should use the grid vector syntax,
F = griddedInterpolant({x,y},z);
where x and y are grid vectors, not meshgrids.
It may also interest you to know that what you are trying to do has already been implemented for you in the File Excahge submission imresizen(),
Unlike imresize(), it requires no toolboxes, but it also doesn't have any of the fancy pre- and post- filtering that imresize uses to improve the quality of the downsampling.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by