how to compare two values

I want to compare two sets of vaues and plot bar graph
apple=[56 90 23 12 34] orange=[23 45 56 90 10] these two in y axis
and in X axis
months=['jan','feb','mar','apr','may']
i need to plot these in different colours
say apple in red
and orange in green
i want to compare in month of jan,feb ,mar,apr,may,how many apples and oranges were there
please help

 채택된 답변

Wayne King
Wayne King 2011년 11월 11일

0 개 추천

apple=[56 90 23 12 34];
orange=[23 45 56 90 10];
data = [apple' orange'];
hbar = bar(data);
set(hbar(1),'facecolor',[1 0 0]);
set(hbar(2),'facecolor',[0 1 0]);
set(gca,'xticklabel',{'jan','feb','mar','apr','may'})

댓글 수: 6

FIR
FIR 2011년 11월 11일
thanks wayne i did not get the colour as i indicated
Wayne King
Wayne King 2011년 11월 11일
do
hbar = bar(data);
set(hbar(1),'facecolor',[1 0 0]);
set(hbar(2),'facecolor',[0 1 0]);
FIR
FIR 2011년 11월 11일
thanks a lot wayne,now is it possible to draw graps for these data using plot command,in y axis the datas are there corresponding to that the plot graph must be marked
Wayne King
Wayne King 2011년 11월 11일
Not sure what you're getting at. Do you mean something like:
plot(data(:,1),'r-^','markerfacecolor',[1 0 0]);
hold on
plot(data(:,2),'g-o','markerfacecolor',[0 1 0]);
FIR
FIR 2011년 11월 11일
exactly wayne thanks a lot,finally ....
months=['jan','feb','mar','apr','may'],these were horizontal in x axis ,can these be made vertical
foe example in bar graph for one bar the x axis label is jan
can this be labelled as
n
a
j
Ilham Hardy
Ilham Hardy 2011년 11월 11일
You can probably use this:
http://www.mathworks.com/matlabcentral/fileexchange/8722
By the way,
the "set(hbar(2),'facecolor',[0 1 0]);" is not correct.
The correct answer should be at least:
"set(hbar(2),'facecolor',[1 0.69 0.39]);"
see?
HTH
ilham

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

FIR
2011년 11월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by