how to write this xlabel like in this example?

2 views (last 30 days)
Please can anyone show me how to add the xlable (A-OSA; A-N; C-N) like the example below?
exemple:
y = [316.45 292.14 319.96; 305.59 287.99 295.21;316.45 292.14 319.96; 305.59 287.99 295.21;...];
316.45 292.14 319.96; 305.59 287.99 295.21;316.45 292.14 319.96; 305.59 287.99 295.21;305.59 287.99 295.21]
box on
bar(y)
set(gca,'xticklabel',{'Pre-test'; 'Post-test';'Pre-test'; 'Post-test'})
ylim([200 360])
ylabel('RT (ms)')
xticks([1 2 3 4 5 6 7 8 9])
xticklabels({'knn','svm','dt','knn','svm','dt','knn','svm','dt'});

Answers (1)

Star Strider
Star Strider on 20 Mar 2021
Try adding this to the end of theposted code:
text(xt(2:3:end), 188*ones(1,3), {'A-OSA','A-N','C-N'}, 'horiz','center', 'vert','top')
so the full code is now:
y = [316.45 292.14 319.96; 305.59 287.99 295.21;316.45 292.14 319.96; 305.59 287.99 295.21;...
316.45 292.14 319.96; 305.59 287.99 295.21;316.45 292.14 319.96; 305.59 287.99 295.21;305.59 287.99 295.21];
box on
hbar = bar(y);
set(gca,'xticklabel',{'Pre-test'; 'Post-test';'Pre-test'; 'Post-test'})
ylim([200 360])
ylabel('RT (ms)')
xticks([1 2 3 4 5 6 7 8 9])
xticklabels({'knn','svm','dt','knn','svm','dt','knn','svm','dt'});
xt = get(gca, 'XTick');
text(xt(2:3:end), 188*ones(1,3), {'A-OSA','A-N','C-N'}, 'horiz','center', 'vert','top')
Experiment with it to get the result you want.
  2 Comments
Star Strider
Star Strider on 20 Mar 2021
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!