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

时间:2015-12-03 17:40:33

标签: matlab fill rose-diagram

我在Matlab中使用rose,我想要将值高于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

然而,填充的三角形不是最大值,我无法弄清楚原因。有什么想法吗?

enter image description here

添加@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

标记最高的

enter image description here

但是对于我得到的原始数据

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

然而当我使用溃败时,我得到了

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

1 个答案:

答案 0 :(得分:2)

查看rout(由rose返回),其中方便地包含模式0 c(i) c(i) 0中的bin计数,用于bin i。如果你设置

test = rout(2:4:end);

您获得所有ncat个分档的bin计数。其余的代码正确地绘制了异常值区。