1

我在 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)))

9

而在使用 rout 时,我得到了

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

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

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

22

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

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

1 回答 1

2

看一下rout(由 返回rose),它方便地包含 bin 的 bin 计数0 c(i) c(i) 0,用于 bins i。如果你设置

test = rout(2:4:end);

你得到所有ncat垃圾箱的垃圾箱计数。您的其余代码正确绘制了异常值箱。

于 2015-12-03T20:04:55.850 回答