Out of memory error on interpolation

조회 수: 2 (최근 30일)
pranto saha
pranto saha 2023년 6월 11일
답변: Walter Roberson 2023년 6월 11일
I am new in matlab. Recently i started some work. But i am stack at a point. I have a data of size = 301 241 46 119. Here some data is missing. But i need to fill all of this data. I tried to use interp3 for this. But i am getting out of memory exception. I also tried in https://matlab.mathworks.com/ Still same error, I need help to solve this problem Here is my code
% Check for missing values
missing_indices = find(isnan(temp_data));
% Identify the coordinates (latitude, longitude, depth, and season) of missing values
[lat_missing, lon_missing, depth_missing, season_missing] = ind2sub(size(temp_data), missing_indices);
% Perform data interpolation for missing values using interp3
temperature_interpolated = interp3(lon, lat, depth, season, temp_data, lon_missing, lat_missing, depth_missing, season_missing, 'linear');
% Replace missing values with the interpolated values
temp_data(missing_indices) = temperature_interpolated;
Error:
Out of memory.
Error in internal.matlab.imagesci.nc/read (line 711)
data(data==fillValue) = NaN;
Error in ncread (line 76)
vardata = ncObj.read(varName, varargin{:});
  댓글 수: 1
Torsten
Torsten 2023년 6월 11일
Where in the examples did you find such a call to "interp3" ?
I only see calls with at most 7 inputs arrays.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2023년 6월 11일
You are not running out of memory in a call to interp3(): you are running out of memory in a call to ncread()
The data file that you are reading is occupies more than 1/2 of your available memory, so when MATLAB tries to compare each data location to the fill value in order to convert fill values to nan, the temporary logical array that is generated fills the rest of remaining memory.
You might possibly be able to do better by using netcdf.open and netcdf.getVar yourself but you might have to disable fill using netcdf.setFill
But you will probably find that in practice what you should be doing is using the ncread start and count parameters so that you are only reading in part of the variable at one time. For example it is often that case that you really only need the data for one timestep at a time -- that even if you are doing an animated plot, the processing on the data often effectively "summarizes" the data down to an array the size of your figure at a time, which can be much more managable.

카테고리

Help CenterFile Exchange에서 NaNs에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by