boxplot

조회 수: 18 (최근 30일)
New
New 2012년 3월 13일
댓글: Benoit Espinola 2020년 6월 10일
I have a matrix of occurences (7 rows(countries),46 columns(number of shoes)), n - number of occurences - for example in "a" I have n1=450, single pair of shoes...
1 2 3 .... 46
a n1 n2 n3 .... n46
b
.
. . g
I would like to produce 7 boxplots representing the distribution in each category a-g. Normally I would have 450 times 1, n2 times 2 etc... is there a simple way to do it? Does anybody have a suggestion for a nicer representation than the boxplot?
Thank you

채택된 답변

Tom Lane
Tom Lane 2012년 3월 16일
This may partially answer what you want. Step 1 would be to take the data for "a" and stretch it out as you describe. Here's one way to expand a data vector according to a vector of frequencies:
f = [4 3 0 1 2]; % frequencies
d = [1 2 3 4 5]; % data
c = [0, cumsum(f)]; % cumulative sum of frequencies
x = zeros(1,c(end));
for j=1:length(c)-1
x(c(j)+1:c(j+1)) = d(j); % insert each value as required
end
  댓글 수: 2
New
New 2012년 3월 18일
Thank you!
Benoit Espinola
Benoit Espinola 2020년 6월 10일
This could become an issue if you have very large frequencies.
For instance:
d = [1 2 3 4 5];
f = [4e10 3e9 0 1e10 2e11];
You could endup with a variable with a length of 2.53e11 (which is massive).
I tried it and I get the following error:
Error using zeros
Requested array exceeds the maximum possible variable size.
How can you deal with such a scenario?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Tom Lane
Tom Lane 2012년 3월 14일
It seems like 1:46 represents your possible data values and [n1 n2 ... n46] represents the frequency of each value. If you "edit mle" and look toward the bottom, it has a little function that expands this sort of representation into a vector with n1 copies of 1, n2 copies of 2, and so on. You could try copying this code to your own function. A warning is that you will need to remove values with a frequency of zero before calling the function.
If you're not comfortable doing this, or if I haven't answered your question, let me know.
  댓글 수: 1
New
New 2012년 3월 15일
Couldn't make it work properly...
Some easier way?
Thanks

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by