Error using bar: inputs must be 2-D
Show older comments
I'm taking a class on Matlab, and for my first homework I need to make bar graphs, separating candidates by gender on one graph and by colleges on the other. I must compare their average salaries. I was able to make the first bar graph, however, I did almost the exact same for the second graph (the one sorted by colleges), but Matlab refuses, citing the error; "Error using bar: inputs must be 2-D". Here's the code:
% Excercise 1 %
univ1 = UniversityofFloridagraduatesalaries(UniversityofFloridagraduatesalaries.gender==1,:)
univ0 = UniversityofFloridagraduatesalaries(UniversityofFloridagraduatesalaries.gender==0,:)
salary0=univ0.salary;
salary1=univ1.salary;
gender=[0, 1];
meanSalary=zeros(1,2);
meanSalary(1)=mean(salary0);
meanSalary(2)=mean(salary1);
bar(gender,meanSalary)
% Excercise 2 %
c_univ1 = UniversityofFloridagraduatesalaries(UniversityofFloridagraduatesalaries.college==1,:)
c_univ2 = UniversityofFloridagraduatesalaries(UniversityofFloridagraduatesalaries.college==2,:)
c_univ3 = UniversityofFloridagraduatesalaries(UniversityofFloridagraduatesalaries.college==3,:)
c_univ4 = UniversityofFloridagraduatesalaries(UniversityofFloridagraduatesalaries.college==4,:)
c_univ5 = UniversityofFloridagraduatesalaries(UniversityofFloridagraduatesalaries.college==5,:)
c_univ6 = UniversityofFloridagraduatesalaries(UniversityofFloridagraduatesalaries.college==6,:)
c_univ7 = UniversityofFloridagraduatesalaries(UniversityofFloridagraduatesalaries.college==7,:)
c_salary1=c_univ1.salary;
c_salary2=c_univ2.salary;
c_salary3=c_univ3.salary;
c_salary4=c_univ4.salary;
c_salary5=c_univ5.salary;
c_salary6=c_univ6.salary;
c_salary7=c_univ7.salary;
college=[1,2,3,4,5,6,7];
c_meanSalary=zeros(1,2,3,4,5,6,7);
c_meanSalary(1)=mean(c_salary1);
c_meanSalary(2)=mean(c_salary2);
c_meanSalary(3)=mean(c_salary3);
c_meanSalary(4)=mean(c_salary4);
c_meanSalary(5)=mean(c_salary5);
c_meanSalary(6)=mean(c_salary6);
c_meanSalary(7)=mean(c_salary7);
bar(college,c_meanSalary)
Note: UniversityofFloridagraduatesalaries is the Excel spreadsheet I imported into a table.
Accepted Answer
More Answers (0)
Categories
Find more on Spreadsheets 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!