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 で Bar Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!