data correction

4 views (last 30 days)
Mahmood dandelion
Mahmood dandelion on 3 Jul 2011
i have a matrix of topographic data. 1356*3039 there are some NaN cells in this matrix that I should remove them. for example like this: 928 926 932 939 970 938 937 936 940 965 949 931 940 928 957 1000 984 NaN 988 987 1108 1094 1121 1117 1068 1253 1285 1313 1226 1169
I want to create a rule to detect such cells and fill them with an interpolation of neighbor cells.
I can not use isnan function for all my data because this is a earth sea topographic data and earth data are also NaN.

Answers (2)

Clemens on 4 Jul 2011
well in some way you will have to use isnan. You could use bwconncomp to find "lonely" Nans. Like in this example:
%%create some sample data
data = rand(10); % make a random sample
data(data>0.9) = NaN; % create some nans
data(1:6,1:6) = NaN; % make an island
c = bwconncomp(isnan(data))
s = cellfun(@numel,c.PixelIdxList)
single_nan_ind = s==1
single_nans = cellfun(@(x) ind2sub(x,size(data)),c.PixelIdxList(single_nan_ind),'UniformOutput',false)
The ones you are looking for would be in single_nans.
Clemens on 4 Jul 2011
Sure just fix the line:
single_nan_ind = s==1
this finds all groups with just one.
So single_nan_ind = s>5 would find islands with more than 5 nans.
I think you get the idea.

Sign in to comment.

Wolfgang Schwanghart
Wolfgang Schwanghart on 3 Jul 2011
you can identify the NaNs using the function isnan.
I = isnan(dem); % where dem is the digital elevation model
The inpaint function by Damian Garcia can be used to fill the gaps.
Cheers, W.
Wolfgang Schwanghart
Wolfgang Schwanghart on 5 Jul 2011
The last line of code should be
demcorrected = roifill(dem,imdilate(I,ones(3)));

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by