Need to set a custom tick label - Bar chart - Numeric values for 'xticklabel' but last tick needs to be alpha characters example - 1,2,3,4,5,6,OAL - How to do

1 view (last 30 days)
Need to set a custom tick label - Bar chart - Numeric values for 'xticklabel' but last tick needs to be alpha characters example - 1,2,3,4,5,6,OAL - How to do

Answers (1)

dpb
dpb on 4 Aug 2015
Edited: dpb on 4 Aug 2015
set(gca,'xticklabel',[num2str([1:6].'); 'OAL'])
NB: are column vector.
ERRATUM
Account for differing string lengths in concatenation; cell strings work for that purpose--
lbl=[{num2str([1:9].','%.1f')};{'OAL'}];
set(gca,'xticklabel',lbl);
  2 Comments
Jerry Vietinghoff
Jerry Vietinghoff on 4 Aug 2015
Edited: dpb on 4 Aug 2015
Thank you but here is a simplified code example:
ty=(rand(1,9));
tyoverall=1.0001;
ty=[ty,tyoverall];
bar(ty);
set(gca,'xticklabel',[num2str(ty(1:9).');'OAL'])
dpb
dpb on 4 Aug 2015
Edited: dpb on 4 Aug 2015
Oh, yeah, the strings aren't same length; use cell strings to handle this...
set(gca,'xticklabel',[{num2str(ty(1:9).','%.1f')};{'OAL'}]);

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!