function for categorizing numerical array by size

So I have an array of numbers, and I am trying to find the occurences of numbers <10,000, occurences of numbers between 10,000 and 50,000, and occurences of numbers of values between 50,000 to 100,000. I am then trying to group these three values into a pie chart. Basically its for a project where I need to show the percentage of people who pay below 10,000, percentage of people who pay between 10,000 and 50,000, and so on.
I know there are numerous way to do this but I think I am just overwhelmed and can't figure out one to go with?
Thanks for help

댓글 수: 4

Would something like this work for you?
% sample array
A = 100000*rand(1000, 1);
% find and plot percentages
freq = sum([A<10000,A>=10000&A<50000,A>=50000])./numel(A);
pie(freq, {'X < $10,000', '$10,000 <= X < $50,000', 'X >= $100,000'});
Tommy
Tommy 2020년 4월 24일
It should work. There are ways to get it to work with your data in the table, also, to avoid converting to a cell array and then string array if possible. But how is your data stored in the table? As numbers or as text?
Tony
Tony 2020년 4월 24일
I got it to work!! Thank yo!!
Tommy
Tommy 2020년 4월 24일
Fantastic, happy to help!

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

답변 (1개)

Steven Lord
Steven Lord 2020년 4월 24일

0 개 추천

Use histcounts.
The histogram function is similar but creates a histogram plot. histcounts just does the binning (no plot) and returns counts which you could then pass into pie or other functions.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2020년 4월 24일

답변:

2020년 4월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by