Get the Isocline from a know levelset plot (Contours) and the function output (Height)
4 ビュー (過去 30 日間)
古いコメントを表示
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1679111/image.png)
- Now, I would like to see the heights of each contour.
- Suppose I have the height value, how do I get the points that belong the contour that corresponds to the height.
Regards...
3 件のコメント
採用された回答
Mathieu NOE
2024 年 4 月 25 日
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)
yco = yc(1:ind-1)
zco = level*ones(size(xco));
plot3(xco,yco,zco,'r','linewidth',5);
2 件のコメント
Mathieu NOE
2024 年 4 月 25 日
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
Mathieu NOE
2024 年 4 月 25 日
I think I just reinvented the wheel !
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!