How to plot a 3d surf plot?
조회 수: 22 (최근 30일)
이전 댓글 표시
I am executing the following code to plot a 3d surface. I get an error. Can I get some help to correct it. Or if there any altternate plots? For every value of z, I have a data of 26 x 26 which needs to be displayed.
clc; clear all;
% Create a sample 3D matrix of size 26 x 26 x 250
% Replace this with your actual data
data = rand(26, 26, 251);
% Define the x, y, and z coordinates
x = linspace(0, 1.5, 26);
y = linspace(0, 1.5, 26);
z = linspace(0,0.025,251);
% Create meshgrids for the x, y, and z coordinates
[X, Y, Z] = meshgrid(x, y, z);
% Create a figure
figure;
% Create a 3D surface plot
surf(X, Y, Z, squeeze(data));
% Customize plot labels and title
xlabel('X Axis (m)');
ylabel('Y Axis (m)');
zlabel('Z Axis');
title('3D Surface Plot');
% Set viewing angle and axis limits as needed
view(3); % 3D view
axis tight; % Tighten the axis limits
colorbar; % Add a color bar
댓글 수: 0
답변 (1개)
Walter Roberson
2023년 8월 13일
You do not have 3D surface. You have a 26 x 26 x 251 cuboid, and you have a data value for each location in the cuboid. That is not a surface, that is a volume
You can use
volumeViewer(data)
but unfortunately volumeViewer and the underlying volshow do not permit setting the scales or limits of the axes.
댓글 수: 3
Walter Roberson
2023년 8월 13일
I do not understand what it means to "club" a color map ? I also do not understand how you are generating a color map from the 26 x 26 slice ?
Have you looked at slice
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!