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 Commenti

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'});
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?
I got it to work!! Thank yo!!
Fantastic, happy to help!

Accedi per commentare.

Risposte (1)

Steven Lord
Steven Lord il 24 Apr 2020
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.

Richiesto:

il 24 Apr 2020

Risposto:

il 24 Apr 2020

Community Treasure Hunt

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

Start Hunting!

Translated by