3D plot from excel data
显示 更早的评论
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
采纳的回答
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 个评论
Hey thanks for this, really helped me out. However i have two questions:
- 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?
- secondly, any way to perform this without any interpolation and just purely from the data provided?
Thank you!
My pleasure.
- 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.
- 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'.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Interpolation 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
