I have a matrix of topographic data, it is a big one. I have replaced land data with NaN and the sea depth data are positive.(a small sample can be seen bellow)
b= [
NaN NaN NaN NaN
4 NaN NaN NaN
19 14 NaN NaN
21 18 14 NaN
24 17 NaN NaN
40 13 NaN NaN
154 26 NaN NaN
232 44 NaN NaN
500 200 100 NaN
200 100 200 NaN
NaN NaN NaN NaN
];
I want to get coastal cells. it should to be: (1,1) (2,2) (3,3) (4,4) (5,3) (6,3) (7,3) (8,3) (9,4) (10,4) (11,3) (11,2) (11,1) so that we can plot a single line contour as coastline.
I read this post MATLAB, what is the best way to trace a boarder in a matrix that is changing each step? but I could not get desired coastline using it. also I write a script as bellow but it returns a tick (2 or 3 cell) line and some breaks in it.
b(~isnan(b))=9; % sea cells will be 9
b(isnan(b))=98672; % land cells will be 98672
for i=1:255
for j=2:119
if b(i,j)==9
if ((b(i,j-1)==98672)||(b(i,j+1)==98672))
b(i,j-1)=333; % 333 will be the coastline
end
if ((b(i-1,j)==98672)||(b(i+1,j)==98672))
b(i,j-1)=333;
end
end
end
end
b(b==98672)=NaN;
b(b==9)=0.001;
pcolor(b);shading flat
the breaks taking place in the points that we have Islands or V shape in coast.
would you help me? please email me too. [email protected]