On Aug 26, 12:12 pm, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
> "Nora " <nursu...@yahoo.com> wrote in message <i540q0$c8...@fred.mathworks.com>...
> > I plot contour map with my dataset and then took the coordinates of these contour levels by contourc command and obtained levels of contours and number of data points belong to these level and coordinates of the data points which create the contour lines. Also, I have a length value (such as 288.45 m). I try to find the coordinate of this length along this contour.
>
> > Level1 Number1
> > x1 y1
> > x2 y2 ==>S1=((x1x2)^2+(y1y2)^2)^0.5
> > x3 y3 ==>S2=...
> > .. ..
> > S1+S2+S3+...+S=288.45
> > S=((xxn)^2+(yyn)^2)^0.5
> > x,y is the result.
> > But, I didnt achieve to make it in a loop. My contour line number changes every time, (I know priorly the length values for each contour line) and I am not good at coding.
> > Hope this time clear.
>
>          
> At last I think I can understand what you are asking, Nora! You want to follow a contour along its line segments a given total chordline distance from one of the ends. Is that right?
>
> The following code is just for one contour. You will have to rewrite it to accommodate a number of contours. Let X be a row vector of the xcoordinates along the contour and Y a row vector of the ycoordinates. Let 'dist' be the distance (288.45 in your example) you wish to go along the contour from the start point.
>
> dX = diff(X); dY = diff(Y);
> s = sqrt(dX.^2+dY.^2); % The lengths of the segments
> c = [0,cumsum(s)]; % Cumulative lengths
> p = find(diff(c>dist)==1); % Find which segment will have (x,y) in it
> if isempty(p) % The quantity 'dist' is too long for the contour
> error('The contour is not that long.')
> else % We have found the segment for (x,y)
> t = (distc(p))/s(p); % Compute the fraction of the way along the segment
> x = X(p)*(1t) + X(p+1)*t; % Find where (x,y) is in the segment
> y = Y(p)*(1t) + Y(p+1)*t;
> end
>
> The point (x,y) is at the required total distance along the contour.
>
> Roger Stafford
Alternatively, once you've calculated c as Roger showed:
x=interp1(c,X,dist);
y=interp1(c,Y,dist);
Note: if dist is outside c, x and y will be NaN.
