2015-07-10 110 views
0

我想用matlab創建圖表,以徑向方式表示質量的數值評估。用matlab中的顏色變量以編程方式生成極座標或準極座標圖

我發現的最好的方法似乎無法正常工作。一個運行下面的代碼:

theta = (0 : (360/11) : 360)*pi/180; 
r = 0 : 2 : 20 ; 
[TH,R] = meshgrid(theta,r); 
[X,Y] = pol2cart(TH,R); 
Z = meshgrid(Data); 
surf(X,Y,Z); 

Data是下述含11個數字,示例數據集是數據的矢量:

Data = 0.884, 0.882, 0.879, 0.880, 0.8776, 0.871, 0.8587, 0.829, 0.811, 0.803, 0.780 

surf這裏的輸出是這樣的:

Incorrect surf plot

我想生成這種類型的圖像更精緻的版本:

mostly correct output

我已經用下面的代碼生成:

for theta = 0 : pi/100 : pi; 
    v = [InterpolatedImageHeight;LengthVector]; 
    x_center = InterpolatedImageHeight((HorizontalRes+1)/2); 
    y_center = 0; %InterpolatedImageHeight((HorizontalRes+1)/2); 
    center = repmat([x_center; y_center], 1, length(InterpolatedImageHeight)); 
    R = [cos(theta) -sin(theta); sin(theta) cos(theta)]; 
    vo = R*(v - center) + center; 
    x_rotated = vo(1,:); 
    y_rotated = vo(2,:); 
    scatter(x_rotated,y_rotated,DotSize,InterpolatedData,'filled'); %x,y,area,color,properties 
end 

這樣做的問題是,它是我在哪裏實質上是使用plot(r,Data),繪製很多很多的副本,並增加散點圖點大小。圖形本身有許多接縫,這需要大量的內存,並且是時間密集的,其中surfmesh將運行得非常快並且佔用最少的內存。

如何產生具有可變輸入顏色的同心環?

回答

0

this thread基於由達倫·羅蘭的代碼,我來了。因此,僅僅通過使用以下行轉的Z的meshgrid以下解決方案:

x = interp1(1:length(data),datax,(datax(1):datax(end)/f:datax(end)),'linear'); 
y = interp1(1:length(datay),datay,datay(1):datay(end)/f:datay(end),'spline'); 
theta = linspace(0,2*pi,n); 

xr = x.'*cos(theta); 
zr = x.'*sin(theta); 
yr = repmat(y.',1,n); 

figure; 
surf(xy,yr,zr,zr*numcolors); 

這是優雅,快速運行,併產生美麗的數字。這是帶有一些額外圖表元素的輸出示例:

sample chart produced by code: Canon EF 50mm f/1.4 Average MTF 30lp/mm map

1

在你的問題中有兩個完全不同的情節。第一個將數據表示爲從原點向圓外的光線。數據點放置在逆時針方向。這方面的一個完善的版本可以實現這樣的:

Data = [0.884, 0.882, 0.879, 0.880, 0.8776, 0.871,... 
     0.8587, 0.829, 0.811, 0.803, 0.780]; 

theta = linspace(0,2*pi,length(Data)); 
r = linspace(0,20,length(Data)); 
[TH,R] = meshgrid(theta,r); 

Z = meshgrid(Data); 
[X,Y,Z] = pol2cart(TH,R,Z); 

surf(X,Y,Z); 
view(2); 
shading interp 

注意我用了linspace產生thetar總是匹配的Data長度。 Z也通過槽pol2cart。然後,您可以使用shading interp刪除補丁之間的線條並插入顏色。通過view(2),您可以設置透視圖,因爲您將擁有2d圖。

這是結果:

result1


這是比較容易得到的結果就像你的第二個例子。數據點代表原點周圍的同心圓,從原點向外界放置。

Z = meshgrid(Data)'; 

這是結果,那麼:

result2