Contour 3D: how to take Z matrix value?

4 次查看(过去 30 天)
dhiraj
dhiraj 2014-5-7
编辑: Prateekshya 2024-10-24,4:38
Hello,
I want to use contour 3D plot command. But anyone can guide me, how I can take Z-axis? i.e. it should be an relation between X and Y (Or expression) would be necessary? I have three single column data (of size 13 x 1). Please provide example, if any.

回答(1 个)

Prateekshya
Prateekshya 2024-10-24,4:34
编辑:Prateekshya 2024-10-24,4:38
Hello Dhiraj,
To create a 3D contour plot in MATLAB, you need a grid of Z values that represent the relationship between your and Y data. If you have three single-column datasets (let us call them X, Y, and Z), you can use these to create a 3D contour plot. However, you need to ensure that your data is structured correctly to form a grid.
Steps to Create a 3D Contour Plot
  • Prepare Data: Ensure that your X, Y, and Z data can form a grid. If Z is a function of X and Y, you will need to create a meshgrid.
  • Use meshgrid: This function helps in creating a grid of and Y values. You can then calculate values for this grid.
  • Plot with contour3: Use this function to create a 3D contour plot.
% Example data
X = linspace(-5, 5, 13)'; % Example X data
Y = linspace(-5, 5, 13)'; % Example Y data
Z = sin(sqrt(X.^2 + Y.^2)); % Example Z data as a function of X and Y
% Create a meshgrid
[XGrid, YGrid] = meshgrid(X, Y);
% Calculate Z values for the grid
ZGrid = sin(sqrt(XGrid.^2 + YGrid.^2)); % Replace with your actual Z function
% Plot the 3D contour
figure;
contour3(XGrid, YGrid, ZGrid, 20); % 20 contour levels
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('3D Contour Plot');
grid on;
The result of this code is:
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by