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

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)

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

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'])
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

Asked:

on 3 Aug 2015

Edited:

dpb
on 4 Aug 2015

Community Treasure Hunt

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

Start Hunting!