2017-01-09 33 views
2

忍受我一分鐘,因爲我解釋了我在做什麼。我有24個角度,介於0到360度之間。在每個角度,我都有一個價值。我想把它作爲一個極地情節的一條線。因此,我的最終結果應該是一個帶有24個小節的極座標圖,每個極圖都指向與弧度相對應的角度方向。這可以在MATLAB或其他繪圖工具中完成嗎?在極座標中創建一個具有震級矢量的圖

+1

是一個[上升情節(https://www.mathworks.com/help/matlab/ref/rose.html )你在找什麼? – Suever

回答

1

我認爲你是polarplot後:

ang_deg = sort(rand(1,24)*360); % some random angles 
ang_rad = ang_deg*pi/180; % convert degrees to radians for polarplot 
values = rand(1,24); % random values to plot 
polarplot(ang_rad, values); 

唉,這個功能在版本2016a介紹。
對於舊版本,請使用polar代替(謝謝Thales指出了這一點)。

+1

對於舊版本的Matlab,'polar(ang_rad,values)'應該做的。 – Thales

+0

我剛剛下載了2016,謝謝! –

1

您可以使用compass爲:

ang = deg2rad(linspace(0,360,24));% angles 
vals = 1:24; % values 
% convert the values to vector components 
U = vals.*cos(ang); 
V = vals.*sin(ang); 
% plot: 
hp = compass(U,V); 

,你會得到:

compass1

但是,如果你想吧,而不是箭頭時,這是一個小更靠譜。之後您繪製從你上面hp應該做到以下幾點:

% get all X and Y data from the plot: 
arrowsX = cell2mat(get(hp,'XData')); 
arrowsY = cell2mat(get(hp,'YData')); 
% delete all arrows head values: 
set(hp,{'XData'},num2cell(arrowsX(:,1:2),2)); 
set(hp,{'YData'},num2cell(arrowsY(:,1:2),2)); 
% make the lines look like bars: 
set(hp,{'LineWidth'},num2cell(ones(24,1)*6)); 

compass2

如果你有Matlab的R2016b您可以使用polarhistogram

ang = deg2rad(linspace(0,360,25));% angles 
vals = 1:24; % values 
polarhistogram('BinEdges',ang,'BinCounts',vals) 

但這裏指定BinEdges使該箱將被收集到ang是一個不太直接,並需要一些操縱:

ang = rand(24,1)*2*pi; % angles 
vals = rand(24,1); % values 
% assuming your data is like 'ang' and 'vals' above: 
data = sortrows([ang vals],1); % sort the data 
% set the width of the bars by the smallest one: 
w = min(diff(sort(ang,'ascend')))*0.5; 
% define the bins location: 
low = max(w,data(:,1)-w); 
high = min(2*pi,data(:,1)+w); 
binEdge = [low high].'; 
% set zeros to all the 'spare' bins: 
counts = [data(:,2) zeros(size(data,1),1)].'; 
counts = counts(:); 
% plot: 
polarhistogram('BinEdges',binEdge(:),'BinCounts',counts(1:end-1)) 

而結果(對一些隨機數據):

compass3