在MatLab中填充玫瑰图中的最大值

o2rvlv0m  于 2022-11-15  发布在  Matlab
关注(0)|答案(1)|浏览(172)

我在MatLab中使用玫瑰色,我想用大于95%(最大离群值)的值将这些三角形涂成红色。我使用了以下通用代码

clear all
close all
ncat = 180;
mydata = rand(360,1).*100;       % random vector
mydata = mydata./max(mydata).*100; % normalize to a max of 100
[tout, rout] = rose(mydata,ncat); % do rose plot with 180 categories

polar(tout, rout);   % getting coordinates
[xout, yout] = pol2cart(tout, rout);
set(gca, 'nextplot', 'add');
test = sum(reshape(mydata(1:360),360/ncat,[])); 
index = find( test >= prctile(test,95)); % get index of outliers
for cindex = index
    fill(xout((cindex-1)*4+1:cindex*4), yout((cindex-1)*4+1:cindex*4), 'r'); % fill outliers red
end
set(gca,'View',[-90 90],'YDir','reverse'); % put 0(360) to top

然而,填充的三角形不是最大值,我不知道为什么。有什么主意吗?

添加@zeeMonkeez建议的解决方案:

% as suggested in the answer
figure
[tout, rout] = rose(mydata,ncat); % do rose plot with 180 categories
polar(tout, rout);   % getting coordinates
[xout, yout] = pol2cart(tout, rout);
set(gca, 'nextplot', 'add');
test = rout(2:4:end);
index = find( test >= prctile(test,95)); % get index of outliers
for cindex = index
    fill(xout((cindex-1)*4+1:cindex*4), yout((cindex-1)*4+1:cindex*4), 'r'); % fill outliers red
end
set(gca,'View',[-90 90],'YDir','reverse'); % put 0(360) to top

是否标记了最高级别的

但对于我得到的原始数据

test1( test1 >= prctile(test1,95))

180.8300 190.7822 190.6257 175.4790 183.1746 196.6801 181.4798 176.1298 198.9011

length(test1( test1 >= prctile(test1,95)))

然而,当使用路由器时,我得到了

test( test >= prctile(test,95))

4 5 5 4 5 4 4 4 5 4 4 6 4 4 5 4 4

length(test( test >= prctile(test,95)))

22
..。跟进下面的评论和答案(非常感谢@ZeeMonkeez),现在我理解了Rose的工作原理,对于那些可能在这里遇到同样问题的人,一个解决方案:

figure
catsize = 30;
counts_by_angle = round(rand(360,1).*100);

ncounts = sum(reshape(counts_by_angle(1:360),catsize,[]));
ncounts = ncounts ./max(ncounts);
bins = ((15:catsize:360)./360).*2.*pi;
cases = ones(1,round(ncounts(1).*100)).*round(bins(1),2);
for icat = 2:length(ncounts)
    cases = [cases  ones(1,round(ncounts(icat).*100)).*round(bins(icat),2)];
end
[tout, rout] = rose(cases,bins);
polar(tout, rout);
[xout, yout] = pol2cart(tout, rout);
set(gca, 'nextplot', 'add');
test = rout(2:4:end);
cindex = find( test > prctile(test,95));
for index = cindex
    fill(xout((index-1)*4+1:index*4), yout((index-1)*4+1:index*4), 'r');
end
set(gca,'View',[-90 90],'YDir','reverse');
k97glaaz

k97glaaz1#

看看rout(由rose返回),它方便地在0 c(i) c(i) 0模式中包含了i的bin计数。如果您设置为

test = rout(2:4:end);

您可以获得所有ncat垃圾箱的垃圾箱计数。代码的其余部分正确地绘制了异常值存储箱。

相关问题