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

 채택된 답변

Star Strider
Star Strider 2021년 4월 22일

3 개 추천

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

Mohammed Saifuddin Ustad
Mohammed Saifuddin Ustad 2023년 4월 21일
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!
Star Strider
Star Strider 2023년 4월 21일
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.
Mohammed Saifuddin Ustad
Mohammed Saifuddin Ustad 2023년 5월 12일
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
Star Strider
Star Strider 2023년 5월 12일
@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'.
Mohammed Saifuddin Ustad
Mohammed Saifuddin Ustad 2023년 5월 12일
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
Star Strider
Star Strider 2023년 5월 12일
I don’t. I looked at other interpolation functions, and they all have essentially the same options, with interp2 also having 'cubic' and 'makima'.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

질문:

2021년 4월 22일

댓글:

2023년 5월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by