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개)
Clemens
2011년 7월 4일
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
Mahmood dandelion
2011년 7월 4일
Clemens
2011년 7월 4일
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.
Wolfgang Schwanghart
2011년 7월 3일
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
Mahmood dandelion
2011년 7월 4일
Wolfgang Schwanghart
2011년 7월 4일
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.
Wolfgang Schwanghart
2011년 7월 5일
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!