Excluding matrix indices which fall outside of a specified area.

2 views (last 30 days)
Hello,
I have a dataset which I have plotted with pcolor. It is based on GPS data for an invasive plant survey (basically walking through the bush). The green indicates areas which were walked directly, the red indicates areas which were in viewing range, and the white inbetween the red and green indicate zones out of a surveyors view. The red blocks along the edge of the plot indicate the boundary of the survey area.
I want to remove the 0 values which fall outside of the survey area (these are the 0 values which continue to the grid's X and Y limits). What I cant wrap my head around is how to remove (or NaN) only the zero values which are not surrounded by data values of 0.5 or 1 (does not need to be a neighbouring grid block).
I want to remove these values so that I can work out the total area which the survey covered compared to the total area of the survey plot (I havent started this yet).
I have attached the pcolor figure and the code block which created the plot.
Thank you in advance,
Nic

Accepted Answer

Mathieu NOE
Mathieu NOE on 16 Nov 2020
hello
this would be my suggestion ...
n = 50;
Z = peaks(n); %returns an n-by-n matrix.
Z = abs(Z);
Z = Z./max(max(Z));
Z(Z<0.33) = 0;
Z(Z>=0.33 & Z<0.66) = 0.5;
Z(Z>=0.66) = 1;
figure(1);pcolor(1:n,1:n,Z);colorbar('vert');
[FX,FY] = gradient(Z);
eq_grad = abs(FX)+abs(FY); % my special equivalent gradient
eq_grad = eq_grad./max(max(eq_grad)); % normalized to 0,1 range
% figure(2);pcolor(1:n,1:n,eq_grad);colorbar('vert');
% create NaN where eq_grad is below threshold and Z < 0.5
ZZ = Z;
thr = 0.001; % gradient threshold slightly above zero
ZZ(ZZ<0.5 & eq_grad <= thr) = NaN ;
figure(3);pcolor(1:n,1:n,ZZ);colorbar('vert');
  4 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Visual Exploration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!