Hello,
I have an excel sheet cointaining x,y,z data in three columns (see attached file).
I would like to plot a 3D graph from this data.
Thanks everyone

 Accepted Answer

Try this:
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/593500/prova_stress.xlsx', 'VariableNamingRule','preserve');
Q1 = T1(1:25,:);
VarNames = T1.Properties.VariableNames;
x = T1{:,1};
y = T1{:,2};
z = T1{:,3};
[Ux,iax,ixx] = unique(x);
[Uy,iay,ixy] = unique(y);
N = 25;
xv = linspace(min(x), max(x), N);
yv = linspace(min(y), max(y), N);
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(x, y, z, Xm, Ym);
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
figure
surfc(Xm, Ym, Zm)
grid on
xlabel(VarNames{1})
ylabel(VarNames{2})
zlabel(VarNames{3})
.

6 Comments

Hey thanks for this, really helped me out. However i have two questions:
  1. Any way to present a legend for the colours of the surface plot, for example the darker tones are for the range of shear stress from 0-1.5, Any way to label that?
  2. secondly, any way to perform this without any interpolation and just purely from the data provided?
Thank you!
My pleasure.
  1. See if the colorbar function will do what you want. There are options to customise it. The clim (previously caxis) function is also an option if you need it.
  2. Not for a surf plot, since it requires that at least the ‘Z’ argument is a matrix. The option for vectors would be limited to a scatter3 plot.
Hey thanks for the help so i have another question my data is mentioned below.
However i was wondering whether there is a way to make my plot smoother, i have tried cubic interpolation and it helps a little. Though i am not able to use pchip and i heard that one would be best. Also can i make the little boxes disappear thanks. Help with this please.
Inserting my data, code and a snippet of the plot.
thanks
my data
0,0,0
0,200,0.236
0,400,0.304
0,600,0.351
0,800,0.387
0,1000,0.404
1,0,0.053
1,200,0.275
1,400,0.350
1,600,0.401
1,800,0.444
1,1000,0.478
2,0,0.118
2,200,0.276
2,400,0.346
2,600,0.398
2,800,0.439
2,1000,0.475
3.5,0,0.213
3.5,200,0.299
3.5,400,0.358
3.5,600,0.409
3.5,800,0.436
3.5,1000,0.478
5,0,0.305
5,200,0.337
5,400,0.401
5,600,0.431
5,800,0.476
5,1000,0.494
7.5,0,0.452
7.5,200,0.481
7.5,400,0.510
7.5,600,0.517
7.5,800,0.558
7.5,1000,0.584
my code using cubic
T1 = readtable('solarcol3.csv');
VarNames = T1.Properties.VariableNames;
x = T1{:,1};
y = T1{:,2};
z = T1{:,3};
[Ux,iax,ixx] = unique(x);
[Uy,iay,ixy] = unique(y);
N = 25;
xv = linspace(min(x), max(x), N);
yv = linspace(min(y), max(y), N);
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(x, y, z, Xm, Ym, 'cubic'); % specify cubic interpolation
figure
surfc(Xm, Ym, Zm)
colorbar
grid on
xlabel('Wind Velocity (m/s)')
ylabel('Heat Flux (W/m2)')
zlabel('Mass Flow Rate (kg/s)')
Image of plot
@Mohammed Saifuddin Ustad — Ideally, this should be a new Question, with the ‘solarcol3.csv’ file uploaded.
It might be possible to make it smoother by increasing ‘N’. To eliminate the surface grid lines, use 'EdgeColor','none'.
okay that i have tried but do you have any idea with pchip interpolaton or any other interpolation that would make this plot better
and sure i will keep that in mind
I don’t. I looked at other interpolation functions, and they all have essentially the same options, with interp2 also having 'cubic' and 'makima'.

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!