Matlab 使用幅值向量在极坐标中创建绘图

Matlab 使用幅值向量在极坐标中创建绘图,matlab,plot,graph,matlab-figure,Matlab,Plot,Graph,Matlab Figure,请耐心听我解释我在做什么。我有24个角度,在0到360度之间。在每个角度,我都有一个值。我想在极坐标图上画一条线。因此,我的最终结果应该是一个极坐标图,上面有24个条,每个条都指向对应的弧度角的方向。这可以在MATLAB或其他绘图工具中完成吗 我想你在追求: 唉,这个功能是在2016a版本中引入的。 对于旧版本,请改用(感谢您指出这一点)。您可以使用: ang = deg2rad(linspace(0,360,24));% angles vals = 1:24; % values % conve

请耐心听我解释我在做什么。我有24个角度,在0到360度之间。在每个角度,我都有一个值。我想在极坐标图上画一条线。因此,我的最终结果应该是一个极坐标图,上面有24个条,每个条都指向对应的弧度角的方向。这可以在MATLAB或其他绘图工具中完成吗

我想你在追求:

唉,这个功能是在2016a版本中引入的。
对于旧版本,请改用(感谢您指出这一点)。

您可以使用:

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));

如果您有Matlab R2016b您可以使用:

但是在这里指定
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))
结果(对于一些随机数据):


是您想要的吗?对于旧版本的Matlab,
polar(ang_rad,values)
应该可以做到这一点。
ang = deg2rad(linspace(0,360,25));% angles
vals = 1:24; % values
polarhistogram('BinEdges',ang,'BinCounts',vals)
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))