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

回答 (1 件)

dpb
dpb 2015 年 8 月 4 日
編集済み: dpb 2015 年 8 月 4 日
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 件のコメント

Jerry Vietinghoff
Jerry Vietinghoff 2015 年 8 月 4 日
編集済み: dpb 2015 年 8 月 4 日
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 2015 年 8 月 4 日
編集済み: dpb 2015 年 8 月 4 日
Oh, yeah, the strings aren't same length; use cell strings to handle this...
set(gca,'xticklabel',[{num2str(ty(1:9).','%.1f')};{'OAL'}]);

サインインしてコメントする。

カテゴリ

製品

質問済み:

2015 年 8 月 3 日

編集済み:

dpb
2015 年 8 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by