3d plots in Matlab similar to Listplot3D in mathematica

时间:2015-06-30 19:23:57

标签: matlab matplotlib wolfram-mathematica

I am trying to plot a 3-D graph using matlab. I am unable to use the "surf" command but when I plot it using the below command I am getting a line plot. I need something like a surface plot. Kindly suggest.

Here's my code

xx=[0.75, 0.8, 0.85, 0.9, 0.95, 1., 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 0.75, 0.8, 0.85, 0.9, 0.95, 1., 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 0.75, 0.8, 0.85, 0.9, 0.95, 1., 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 0.75, 0.8, 0.85, 0.9, 0.95, 1., 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 0.75, 0.8, 0.85, 0.9, 0.95, 1., 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 0.75, 0.8, 0.85, 0.9, 0.95, 1., 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 0.75, 0.8, 0.85, 0.9, 0.95, 1., 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 0.75, 0.8, 0.85, 0.9, 0.95, 1., 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 0.75, 0.8, 0.85, 0.9, 0.95, 1., 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 0.75, 0.8, 0.85, 0.9, 0.95, 1., 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 0.75, 0.8, 0.85, 0.9, 0.95, 1., 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5];
yy=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1];
zz=[733.544, 630.535, 547.164, 479.489, 424.148, 378.498, 340.493, 308.56, 281.5, 258.383,238.468, 221.208, 206.13, 192.895, 181.194, 170.811, 761.517, 656.231, 570.406, 500.42, 442.994, 395.509, 355.894, 322.565, 294.288, 270.106, 249.262, 231.175, 215.385, 201.499, 189.235, 178.336, 789.005, 681.657, 593.518, 521.289, 461.821, 412.513, 371.31, 336.583, 307.085, 281.835, 260.063, 241.149, 224.624, 210.102, 197.26, 185.847, 815.984, 706.814, 616.488, 542.089, 480.609, 429.514, 386.728, 350.612, 319.893, 293.572, 270.857, 251.124, 233.869, 218.69, 205.269, 193.342, 842.45, 731.704, 639.313, 562.821, 499.384, 446.518, 402.147, 364.654, 332.711, 305.318, 281.659, 261.091, 243.1, 227.271, 213.27, 200.821, 868.394, 756.319, 662.007, 583.49, 518.139, 463.509, 417.582, 378.701, 345.54, 317.073, 292.469, 271.065, 252.332, 235.843, 221.252, 208.275, 893.798, 780.654, 684.553, 604.092, 536.854, 480.51, 433.031, 392.758, 358.38, 328.837, 303.285, 281.034, 261.553, 244.401, 229.218, 215.712, 918.66, 804.707, 706.953, 624.627, 555.551, 497.495, 448.47, 406.826, 371.229, 340.61, 314.094, 291.001, 270.773, 252.955, 237.174, 223.133, 942.963, 828.462, 729.205, 645.094, 574.228, 514.49, 463.925, 420.908, 384.09, 352.389, 324.91, 300.973, 279.982, 261.488, 245.109, 230.535, 966.693, 851.924, 751.311, 665.484, 592.874, 531.469, 479.394, 435.002, 396.96, 364.17, 335.735, 310.933, 289.187, 270.017, 253.028, 237.909, 989.834, 875.08, 773.252, 685.803, 611.488, 548.457, 494.864, 449.108,409.842,375.959,346.559,320.897,298.384,278.529,260.936,245.266];
scatter3(xx,yy,zz)

1 个答案:

答案 0 :(得分:1)

Matlab surfmesh命令在输入中使用矩阵(而非矢量)。

您的xxyy数据已经代表了一个网格,但它们并没有这样组织。

简单地reshape你的向量以形成一个网格,你可以使用Matlab函数:

X = reshape(xx,16,[]) ;
Y = reshape(yy,16,[]) ;
Z = reshape(zz,16,[]) ;

figure
subplot(1,2,1) ; surf(X,Y,Z)
subplot(1,2,2) ; mesh(X,Y,Z)

surfandmesh