data correction

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.

回答(2 个)

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.

2 个评论

thank you
it works.
is there any way to find islands with 2 or more nan cells?
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.

请先登录,再进行评论。

Hi,
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.

3 个评论

thank you
but I said that I cannot use isnan, because I have some data that should be 'nan'. I want to find the nan cells that all 8 cells around them were not nan and also data cells that have the same position due to nan cells.
I am trying to write a script that allow me to find cells that rounded by a range of data in special radius.
for example if a(i,j)=nan then a(i-1:i+1,j-1) & a(i-1:i+1,j+1) & a(i-1,j) & a(i+1,j) ((8 cells around i,j)) were all nan this called radius 1 and ...
Well, then use isnan and brush the data such that only regions of nans remain that are smaller than a specified number of cells (k).
k = 1;
I = isnan(dem);
I = xor(bwareaopen(I,k+1),I);
demcorrected = roifill(dem,I);
I didn't try it since I just have Matlab not at hand, but it should work.
The last line of code should be
demcorrected = roifill(dem,imdilate(I,ones(3)));

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Scatter Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by