Plotting 3D mesh from 3 data columns

17 visualizzazioni (ultimi 30 giorni)
Bendix
Bendix il 23 Nov 2022
Commentato: Bendix il 28 Nov 2022
I have an excel file with 3 colums (X,Y and Z coordiantes) which i would like to plot as a surface (heat map) in 3D. Preferably I would like my x and y axis to be shown with the following lengths: x = 0 - 11.5 and y = 0 - 7.6

Risposta accettata

Sakshay
Sakshay il 28 Nov 2022
Hi Bendix,
As per my understanding, you are trying to create a 3D surface plot from X,Y,Z points.
You need to interpolate the points to plot them as a surface. The points can be interpolated using the "griddata()" function. The following example will illustrates how to do that:
% Read the data points as a matrix
T = readmatrix('3DPlot.xlsx');
% Create a meshgrid for plotting
[xq,yq] = meshgrid(0:.2:11.5, 0:.2:7.6);
% Interpolate the points using griddata function
vq = griddata(t(:, 1), t(:, 2), t(:, 3),xq,yq);
% Plot the surface
mesh(xq,yq,vq);
hold on;
% Plot the points
plot3(t(:, 1), t(:, 2), t(:, 3),'o');
% Set the X and Y Limits
xlim([0 11.5]);
ylim([0 7.6]);
Please refer to the following documentation for more information on "griddata()" function:
  1 Commento
Bendix
Bendix il 28 Nov 2022
Perfect, thank you very much and thanks for the explanations of the lines! Just a small correction, the first varable should be lower case t and it works like a charm

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by