Editing tick marks figure

15 views (last 30 days)
Floris Zoutman
Floris Zoutman on 17 Sep 2012
Commented: Voss on 2 Jan 2024
I'm trying to add extra tick marks to my figure for percentiles of my sample, but I got a little stuck on how to do it. My current tick marks are coded like this: xt=(0:30000:150000)'; xtl=sprintf('%d |',xt'); set(gca,'xtick',xt) set(gca,'xticklabel',xtl);
Now I would like to add three more tickmarks in (vector) variable PERC and label them respectively P25, P50 and P75. I think it should be easy to adapt xt: xt=[xt;PERC'] . However, I don't understand how to edit variable xtl. Can anybody help me out on how to do it?

Answers (1)

Voss
Voss on 2 Jan 2024
xlim([0 200000])
xt=0:30000:150000;
xtl=compose('%d',xt);
PERC = [45000 100000 130000]; % say
xt=[xt PERC];
xtl=[xtl 'P25' 'P50' 'P75'];
[~,idx] = sort(xt);
xt = xt(idx);
xtl = xtl(idx);
set(gca,'xtick',xt,'xticklabel',xtl);
  1 Comment
Voss
Voss on 2 Jan 2024
What I would've done in 2012:
xlim([0 200000])
xt=0:30000:150000;
xtl=strtrim(cellstr(num2str(xt(:)))).';
PERC = [45000 100000 130000]; % say
xt=[xt PERC];
xtl=[xtl 'P25' 'P50' 'P75'];
[~,idx] = sort(xt);
xt = xt(idx);
xtl = xtl(idx);
set(gca,'xtick',xt,'xticklabel',xtl);

Sign in to comment.

Categories

Find more on Install Products in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!