- 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
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Vidhi Agarwal
il 4 Dic 2024
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 Commenti
Vedere anche
Categorie
Scopri di più su Contour Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!