Ploting a Bar graph based on the amount of specific values in a colum
1 view (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Divya Yerraguntla
on 23 Sep 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!
0 Comments
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!