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

조회 수: 1 (최근 30일)
Andrej Voroncov
Andrej Voroncov 2019년 8월 29일
답변: Divya Yerraguntla 2019년 9월 23일
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?

답변 (1개)

Divya Yerraguntla
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!

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by