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

fill max values in a rose plot in matlab

我在 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),现在我了解了 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');

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

test = rout(2:4:end);

您将获得所有 ncat 个箱子的箱子计数。您的其余代码正确地绘制了离群值箱。