简体   繁体   中英

Matlab 3d plot of 3 vectors

I have these 3 vectors,and I need a 3D graph of them.
X and Y are the coordinates and Z is the energy. The problem could probably be solved with griddata or interp2 - but I dont really understand how to deal with them.

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:

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 .
Of course you can replace the 'cubic' interpolation by a 'linear' one..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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