how to write this xlabel like in this example?

1 Ansicht (letzte 30 Tage)
benghenia aek
benghenia aek am 20 Mär. 2021
Kommentiert: Star Strider am 20 Mär. 2021
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'});

Antworten (1)

Star Strider
Star Strider am 20 Mär. 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 Kommentare
benghenia aek
benghenia aek am 20 Mär. 2021
Thank you so much Mr Star Strider
Star Strider
Star Strider am 20 Mär. 2021
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by