Get the Isocline from a know levelset plot (Contours) and the function output (Height)

13 views (last 30 days)
I was checking the function fcontour that we can use to get the contours like the following one.
I took the given example:
f = @(x,y) exp(-(x/3).^2-(y/3).^2) + exp(-(x+2).^2-(y+2).^2);
fc = fcontour(f)
  1. Now, I would like to see the heights of each contour.
  2. Suppose I have the height value, how do I get the points that belong the contour that corresponds to the height.
Regards...
  3 Comments
Prasanna Routray
Prasanna Routray on 25 Apr 2024
Thanks Mathieu for quick response.
I may have posted confusing message.
Here is what I want to do.
  1. I have the equation for the function and I can plot the isoclines.
  2. Now suppose I want to know the set of X,Y that generate an isocline for a given z value.
For example, if I know the value of Z=0.04;
Now, how do I get the set of {X,Y} that that gives me Z=0.04;
Also, I could not explicitely mention that I would like to see the 3D view so that I can see the contours and height in a 3D plot.
Hope this makes some sense about what I'm trying to do.

Sign in to comment.

Accepted Answer

Mathieu NOE
Mathieu NOE on 25 Apr 2024
here a demo if you have one isocline , here I assumed we want only the outer portion (there could be also an inner isocline at same height)
the x,y coordinates are stored in xco, yco in my code
Z = peaks(50)/10;
level = 0.04;
surf(Z)
hold on
% extract outer isocline
[C,h] = contour(Z,level*[1 1]);
xc = C(1,2:end);
yc = C(2,2:end);
ind = find(xc==level);
% outer isocline
xco = xc(1:ind-1)
xco = 1x169
13.3759 14.0000 15.0000 16.0000 17.0000 17.7002 18.0000 19.0000 19.9474 20.0000 21.0000 21.8908 22.0000 23.0000 23.6349 24.0000 25.0000 25.1659 26.0000 26.4512 27.0000 27.5005 28.0000 28.3683 29.0000 30.0000 30.0682 31.0000 31.2237 32.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
yco = yc(1:ind-1)
yco = 1x169
14.0000 13.4968 13.2686 13.3839 13.6826 14.0000 14.0918 14.5291 15.0000 15.0203 15.5194 16.0000 16.0534 16.6215 17.0000 17.2345 17.8957 18.0000 18.6827 19.0000 19.6098 20.0000 20.7778 21.0000 21.9719 21.1263 21.0000 20.2419 20.0000 19.4384
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
zco = level*ones(size(xco));
plot3(xco,yco,zco,'r','linewidth',5);
  2 Comments
Mathieu NOE
Mathieu NOE on 25 Apr 2024
a more general code allows you to access multiple isoclines x,y coordinates (if several isoclines exist at a given z level)
here we have 2 isoclines at h = 0.04 (see blue and orange traces)
Z = peaks(50)/10;
level = 0.04;
surf(Z)
hold on
% extract all isocline for a given level
[C,h] = contour(Z,level*[1 1]);
[m,n] = size(C);
ind = find(C(1,:)==level); % index of beginning of each isocline data in C
ind = [ind n+1]; % add end (+1)
for k = 1:numel(ind)-1
xc = C(1,ind(k)+1:ind(k+1)-1);
yc = C(2,ind(k)+1:ind(k+1)-1);
zc = level*ones(size(xc));
plot3(xc,yc,zc,'linewidth',5);
end
hold off

Sign in to comment.

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!