필터 지우기
필터 지우기

How to plot a 3d surf plot?

조회 수: 15 (최근 30일)
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota 2023년 8월 13일
댓글: Kalasagarreddi Kottakota 2023년 8월 13일
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));
Error using matlab.graphics.chart.primitive.Surface
Value must be a vector or 2D array of numeric type.

Error in surf (line 145)
hh = matlab.graphics.chart.primitive.Surface(allargs{:});
% 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

답변 (1개)

Walter Roberson
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
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
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota 2023년 8월 13일
Thanks, @Walter Roberson, Slice looks a good option

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by