Ploting a Bar graph based on the amount of specific values in a colum
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Divya Yerraguntla
2019-9-23
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!