Add XTickLabels names from cells array

16 vues (au cours des 30 derniers jours)
Stefano Cucchi
Stefano Cucchi le 25 Jan 2022
Commenté : Stefano Cucchi le 25 Jan 2022
Hello,
i need to add label names to a bar plot. Every bar refers to a channel name that is contained in a cell array named "nome_canali".
The total number of bars (N) is n_canali*n_try :Example: (n_canali=5, n_try=2 => N=10). So, i need to reiterate the names of the cell array two times in order to give to each bar his name instead of the numbers.
I tried with this but obviously it doesn't work:
  • figure
  • subplot(2,1,1)
  • bar(RMS)
  • set(gca,'XTick',[1:(n_canali*n_try)],'XTickLabel',{nome_canali});
How can i solve this problem?
Thank you, Stefano

Réponse acceptée

Ankit
Ankit le 25 Jan 2022
Modifié(e) : Ankit le 25 Jan 2022
@Stefano Cucchi I hope this is what you are looking for?
n_canali = 5;
n_try = 2;
nome_canali = {'ai0' 'ai1' 'ai3' 'ai4' 'ai7'};
y = [75 91 105 123.5 131 150 179 203 226 249];
bar(y);
set(gca,'XTick',1:(n_canali*n_try),'XTickLabel',nome_canali);
  1 commentaire
Stefano Cucchi
Stefano Cucchi le 25 Jan 2022
Now it's working! It was a small mistake.
Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by