Highlight highest bar in bar chart matlab

Is there anyway to highlight/mark the highest or lowest bar in matlab? I'm using the following code to plot bar chart
r2=10,20,30
figure;
bar(r2,'m');
set(gca,'XTickLabel',{'a','b','c'})
set(gca,'YTickLabel',{r2})
xlabel('shops');
ylabel('distance in kilometers')
please tell me how can i highlight highest bar i.e. 30 or lowest i.e. 10 ?

댓글 수: 2

the cyclist
the cyclist 2013년 7월 13일
Can you be more specific on what you mean by "highlight"? Do you want it to be a different color, or have some text over it that says "highest", or what?
Sarah
Sarah 2013년 7월 13일
Yes, anything that makes the highest or lowest bar prominent like giving it a different color or placing some text over it or marking its peak with a cross etc..

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

 채택된 답변

the cyclist
the cyclist 2013년 7월 13일

0 개 추천

Here is one way:
r2=[10,20,30];
[maxBar,maxIndex] = max(r2);
[minBar,minIndex] = min(r2);
figure;
bar(r2,'m');
text(maxIndex-0.05,maxBar+2,'Max')
text(minIndex-0.05,minBar+2,'Min')
set(gca,'XTickLabel',{'a','b','c'})
ylim([0 maxBar+5])
set(gca,'YTick',r2)
set(gca,'YTickLabel',{r2})
xlabel('shops');
ylabel('distance in kilometers')

댓글 수: 2

Its giving this error !
Subscript indices must either be real positive integers or
logicals.
Error in ==> gps1 at 46 text(maxIndex-0.05,maxBar+2,'Max')
Sarah
Sarah 2013년 7월 13일
However it's working outside my program.. Thanks alot! I'll fix it my way..

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

추가 답변 (0개)

카테고리

제품

태그

질문:

2013년 7월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by