- contour: https://www.mathworks.com/help/matlab/ref/contour.html
- contourf: https://www.mathworks.com/help/matlab/ref/contourf.html
Draws a 3D hidden function iso-high line
2 ビュー (過去 30 日間)
古いコメントを表示
I used the isosurface function to draw an image of the hidden function, and I wanted to show contours below the 3D graph.
The code is followed.
function sita45
[x,y,z]=meshgrid(linspace(0,0.04,300),linspace(0,0.5,300),linspace(0,0.2,200));
v=(3*log10(x)-182*x-15.079*y+2*log10(z)-48.912*z+15.62);
p=patch(isosurface(x,y,z,v,0));
view(3)
set(p, 'FaceColor', 'blue', 'Edgecolor', 'none');
camlight('headlight');lighting phong
Thank you for your help!
0 件のコメント
回答 (1 件)
Vidhi Agarwal
2024 年 12 月 4 日
Hi @跻 陈
To enhance your 3D plot with contours below the graph in MATLAB, you can use the "contour" or "contourf" functions to add contour lines to the 2D projection on one of the coordinate planes.
Below is the modified code for the same:
function sita45
% Define the grid
[x, y, z] = meshgrid(linspace(0, 0.04, 300), linspace(0, 0.5, 300), linspace(0, 0.2, 200));
% Define the function values
v = (3*log10(x) - 182*x - 15.079*y + 2*log10(z) - 48.912*z + 15.62);
% Create the isosurface
p = patch(isosurface(x, y, z, v, 0));
set(p, 'FaceColor', 'blue', 'EdgeColor', 'none');
% Add lighting and view
camlight('headlight');
lighting phong;
view(3);
hold on;
% Add contours on the bottom plane (z = 0)
% Extract the slice at z = 0
[X, Y] = meshgrid(linspace(0, 0.04, 300), linspace(0, 0.5, 300));
% Use a small z value to avoid log(0)
V_slice = (3*log10(X) - 182*X - 15.079*Y + 2*log10(0.0001) - 48.912*0.0001 + 15.62);
% Plot contours
contour(X, Y, V_slice, 20, 'LineColor', 'black'); % Adjust the number of contour levels as needed
% Set axis labels
xlabel('X');
ylabel('Y');
zlabel('Z');
% Set other plot properties
axis tight;
grid on;
hold off;
end
For better understanding of "contour" or "contourf" refer to the following documentation:
Hope this helps!
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!