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);
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);
你得到:
但是,如果你想要酒吧而不是箭头,那就更棘手了 . 从上面绘制 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));
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))
2 回答
我想你是在polarplot之后:
唉,这个功能是在2016a版本上引入的 .
对于旧版本,请改用polar(感谢Thales指出这一点) .
您可以使用compass:
你得到:
但是,如果你想要酒吧而不是箭头,那就更棘手了 . 从上面绘制
hp
后,您应该执行以下操作:If you have Matlab R2016b 你可以使用polarhistogram:
但是在这里指定
BinEdges
以便将二进制位移到ang
是一个不太直接的,需要一些操作:结果(对于一些随机数据):