2012-09-28 113 views
0

3D图形我想以此来创建三维表面:设置彩条的范围在MATLAB

>> a=X 

a = 

Columns 1 through 8 

      0   50   100   150   200   250   300   350 

Columns 9 through 16 

     400   450   500   550   600   650   700   750 

Columns 17 through 21 

     800   850   900   950  1000 

>> b=Y 

b = 

    0 
    50 
    100 
    150 
    200 
    250 
    300 
    350 
    400 

>> c=Z 

c = 
Columns 1 through 8 

      0   0   0   0   0   0   0   0 
      16   32   67   98   127   164   194   234 
     120   171   388   773  1086  1216  1770  2206 
     189   270   494  1978  2755  3134  5060  10469 
     133   166   183   348   647   937  1446  2304 
     192   162   154   113   161   189   266   482 
      0   0   0   0   0   0   0   0 
      0   0   0   0   0   0   0   0 
      0   0   0   0   0   0   0   0 

Columns 9 through 16 

      0   0   0   0   0   0   0   0 
     366   604   529   504   346   226   228   179 
     4027  11186  10276  5349  2560  1322   996   799 
     27413  76387  37949  15591  5804  2654  1803  1069 
     9844  24152  14772  4613  1777   849   459   290 
     1288  2623  1538   582   280   148   90   56 
      0   0   0   0   0   0   0   0 
      0   0   0   0   0   0   0   0 
      0   0   0   0   0   0   0   0 

Columns 17 through 21 

      0   0   0   0   0 
     108   94   79   0   0 
     646   476   612   0   0 
     884   858   722   0   0 
     266   215   139   0   0 
      48   48   31   0   0 
      0   0   0   0   0 
      0   0   0   0   0 
      0   0   0   0   0 



>> surf(X,Y,Z) 

同时我想限定的Z值< = 1803将与红色显示颜色在表面图上,1803 < Z < 2755黄色和Z> = 2755绿色。色条的极限可以是Z的最小值和最大值(从0到76387)。如何设置颜色条的范围以获得此结果?

回答

2

,你问这个会做:

%# add red (row 1), yellow (row 2), green (row 2) 
map = [1 0 0; 0 1 1; 0 1 0]; 

%# set the new map as the current map 
colormap(map); 

colors = zeros(size(c));   %# create colors array   
colors(c <= 1803) = 1;   %# red (1) 
colors(c > 1803 & c < 2755) = 2; %# yellow (2) 
colors(c >= 2755) = 3;   %# green (3) 

%# and pass it into surf  
surf(a,b,c, colors)