function for categorizing numerical array by size
Afficher commentaires plus anciens
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 commentaires
Tommy
le 24 Avr 2020
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
le 24 Avr 2020
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
le 24 Avr 2020
Tommy
le 24 Avr 2020
Fantastic, happy to help!
Réponses (1)
Steven Lord
le 24 Avr 2020
0 votes
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.
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!