How do I plot 3d graph ?

4 ビュー (過去 30 日間)
Urvashi Agrawal
Urvashi Agrawal 2021 年 5 月 24 日
コメント済み: Star Strider 2021 年 5 月 25 日
So I have this 26x4 matrix and I need to plot a 3d matrix for the first 3 coloumns. The following is my code :
impval = xlsread('Values_sweep.xlsx');
vol_data = impval(1:end,1); %data.VolumeSystem
density_data = impval(1:end,2); %data.PowerDensity
power_data = impval(1:end,3);%data.Power
distance_data = impval(1:end,4);%data.distance
x = vol_data;
y = power_data;
z = density_data;
[X,Y] = meshgrid(x,y);
How do I then plot in 3d. I want to plot for the vol_data, density_data and power_data but I'm getting error 'Z must be a matrix , not a scalar or vector'

回答 (2 件)

Jonas
Jonas 2021 年 5 月 24 日
what about plot3(x,y,z) without the meshgrid?
  1 件のコメント
Urvashi Agrawal
Urvashi Agrawal 2021 年 5 月 24 日
I tried it , but I'm more interested in having a proper surface /mesh grid plot .

サインインしてコメントする。


Star Strider
Star Strider 2021 年 5 月 24 日
Interpolate!
N = 50;
xv = linspace(min(x), max(x), N);
yv = linspace(min(y),m max(y), N);
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(x, y, z, Xm, Ym);
figure
surfc(Xm, Ym, Zm)
grid on
See the griddata documentation for details.
This is prototype code. Note than ‘N’ can be any value that works, and does not have to be the same for both ‘xv’ and ‘yv’.
.
  2 件のコメント
Urvashi Agrawal
Urvashi Agrawal 2021 年 5 月 25 日
Not exactly what I was hoping..
Star Strider
Star Strider 2021 年 5 月 25 日
The data are the data.
Note — The x-axis is the scale of the y-axis and z-axis. If you want to plot it as a (relatively narrow) surface that may be more representative, use:
axis('equal')
after the surf call.
If you plot it with plot3 or scatter3, the plot should look similar to what you got with my code. Another option is stem3 if you want to see precisely where on the (x,y) plane the points originated.
.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by