Effacer les filtres
Effacer les filtres

How to plot a 3d surf plot?

14 vues (au cours des 30 derniers jours)
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota le 13 Août 2023
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
% 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

Réponses (1)

Walter Roberson
Walter Roberson le 13 Août 2023
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
but unfortunately volumeViewer and the underlying volshow do not permit setting the scales or limits of the axes.
  3 commentaires
Walter Roberson
Walter Roberson le 13 Août 2023
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 le 13 Août 2023
Thanks, @Walter Roberson, Slice looks a good option

Connectez-vous pour commenter.


En savoir plus sur Lighting, Transparency, and Shading dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by