Line | |
---|
1 | function c = cut_diverging(x,n)
|
---|
2 | % CUT_DIVERGING Index of sign-balanced quantiles
|
---|
3 | % cut_diverging(x,n) is just like cut_quantile(x,n) except the negative and
|
---|
4 | % positive numbers are each divided into n/2 quantiles.
|
---|
5 | % In other words, it cuts x into n parts so that half go to x<0.
|
---|
6 | %
|
---|
7 | % Examples:
|
---|
8 | % cut_diverging(-2:3,2)
|
---|
9 | % cut_diverging(-2:3,3)
|
---|
10 |
|
---|
11 | n1 = floor(n/2);
|
---|
12 | n2 = n - n1;
|
---|
13 | ineg = find(x(:) < 0);
|
---|
14 | i0 = find(x(:) == 0);
|
---|
15 | ipos = find(x(:) > 0);
|
---|
16 | c = zeros(size(x));
|
---|
17 | c(i0) = n1+1;
|
---|
18 | c(ineg) = cut_quantile(x(ineg),n1);
|
---|
19 | c(ipos) = cut_quantile(x(ipos),n2-1)+n1+1;
|
---|
Note: See
TracBrowser
for help on using the repository browser.