简体   繁体   English

Matlab 3D向量的3D图

[英]Matlab 3d plot of 3 vectors

I have these 3 vectors,and I need a 3D graph of them. 我有这三个向量,我需要它们的3D图。
X and Y are the coordinates and Z is the energy. X和Y是坐标,Z是能量。 The problem could probably be solved with griddata or interp2 - but I dont really understand how to deal with them. 这个问题可能可以用griddata或interp2解决-但是我真的不明白如何处理它们。

x = [703 704 705 706 762 760 762 764 766 766 771 771 ...
   828 831 502 836 891 892 895 318 320 379 379 382 383 ...
   384 442 443 444 444 445 447 449 511 508 511 509 509 ...
   510 509 510 574 573 573 573 573 573 574 576 575 578 ...
   635 635 634 637 637 639 641 642 643 827 827 828 644 ...
   697 697 891 698 699 892 704];

y = [498 563 629 692 179 241 305 371 435 498 561 624 ...
   429 496 176 559 374 430 565 502 565 374 439 505 569 ...
   631 183 312 375 440 501 567 631 247 309 373 438 502 ...
   566 628 694 181 244 308 372 437 502 565 629 693 755 ...
   181 245 310 372 436 500 564 629 693 244 308 371 755 ...
   180 244 308 308 372 503 436];

z = [71172.63 59691.115 41209.71 45061.89 59223.98 ...
   42330.585 41934.85 66172.105 45911.76 45078.01 68746.4 ...
   51346.567 57932.58 48625.975 42202 44483.783 62927.595 ...
   53761.958 43314.128 42754.26 31610.293 45376.275 34661.647 ...
   35105.147 39571.948 38936.785 83547.518 39633.85 44048.802 ...
   35590.97 49392.215 38008.345 42108.543 47486 26103 28599 ...
   31419 29271.158 41591.745 32203.217 35669.092 50788.315 ... 
   29967.715 30581.138 30694.737 33782.143 40074.855 28531.265 ...
   38337.658 31429.015 33893.448 58948.058 39229.93 39465.64 ...
   37449.57 40265.768 43811.802 42839.647 50270.707 55402.198 ...
   54075.66 43573.7325 38312.1075 57198.402 58962.967 50880.345 ...
   52337.115 59699.333 43770.645 55210.7025 77166.775];

you can create a 3d picture with an interpolated mesh: 您可以创建带有插值网格的3d图片:

x=[703 704 705 706 762 760 762 764 766 766 771 771 828 831 502 836 891 892 895 318 320   379 379 382 383 384 442 443 444 444 445 447 449 511 508 511 509 509 510 509 510 574 573 573 573 573 573 574 576 575 578 635 635 634 637 637 639 641 642 643 827 827 828 644 697 697 891 698 699 892 704]
y=[498 563 629 692 179 241 305 371 435 498 561 624 429 496 176 559 374 430 565 502 565 374 439 505 569 631 183 312 375 440 501 567 631 247 309 373 438 502 566 628 694 181 244 308 372 437 502 565 629 693 755 181 245 310 372 436 500 564 629 693 244 308 371 755 180 244 308 308 372 503 436]
z=[71172.63 59691.115 41209.71 45061.89 59223.98 42330.585 41934.85 66172.105 45911.76 45078.01 68746.4 51346.567 57932.58 48625.975 42202 44483.783 62927.595 53761.958 43314.128 42754.26 31610.293 45376.275 34661.647 35105.147 39571.948 38936.785 83547.518 39633.85 44048.802 35590.97 49392.215 38008.345 42108.543 47486 26103 28599 31419 29271.158 41591.745 32203.217 35669.092 50788.315 29967.715 30581.138 30694.737 33782.143 40074.855 28531.265 38337.658 31429.015 33893.448 58948.058 39229.93 39465.64 37449.57 40265.768 43811.802 42839.647 50270.707 55402.198 54075.66 43573.7325 38312.1075 57198.402 58962.967 50880.345 52337.115 59699.333 43770.645 55210.7025 77166.775]

% interpolation on regular grid
xlin=linspace(min(x),max(x),50);
ylin=linspace(min(y),max(y),50);
[X,Y]=meshgrid(xlin,ylin);
Z=griddata(x,y,z,X,Y,'cubic'); 

% visualization
mesh(X,Y,Z);
axis tight; hold on
plot3(x,y,z,'.', 'MarkerSize',15)
xlabel('x')
ylabel('y')
%surf(X,Y,Z)

The result looks like: 结果看起来像: 在此处输入图片说明

The code is explained in detail by doug on his site . 道格(Doug)在他的网站上详细解释了该代码。
Of course you can replace the 'cubic' interpolation by a 'linear' one.. 当然,您可以将“三次”插值替换为“线性”插值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM