Ploting a Bar graph based on the amount of specific values in a colum

1 visualizzazione (ultimi 30 giorni)
I have two columns with c1 being a list of ages and c15 being if they earn more the 50k or less than 50k,(two categories).I was wondering how I could make a bar graph with the age as x axes (as a category) and a bar with a height corresponding to the % earning over 50k
for now all i have is this
c1 = CensusTrainTable{:,1};
c15 = CensusTrainTable{:,15};
How do I count the amount earned over 50 for just a specific age and then plot it?

Risposte (1)

Divya Yerraguntla
Divya Yerraguntla il 23 Set 2019
Hi Andrej,
I'm assuming that you are trying to plot the ages of people with salary greater than 50K on X-axis and the amount by which the salary is greater than 50K on Y-axis. Try using the following code to do so:
% Convert the cell arrays to matrices
c1 = cell2mat(c1);
c15 = cell2mat(c15);
% Get the ages of people with income greater than 50K
c1 = c1(c15>50);
% Get the amount of income greater than 50K for the ages and save it as variable n
n = c15(c15>50)-50;
bar(c1,n);
Hope it helps!

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by