plot of a string vector vs numeric vector

15 vues (au cours des 30 derniers jours)
Hassan
Hassan le 24 Juin 2011
Modifié(e) : Stephen23 le 13 Avr 2017
I wonder how to make a plot as X-axis is a text vector. I get an error when I run the folloing code (??? Error using ==> plot Invalid first data argument). I apperciate your help.
y=[1 2 3 4 5 6]
x=['a','b','c','d','e','f']
plot(x,y)
  1 commentaire
Stephen23
Stephen23 le 13 Avr 2017
Modifié(e) : Stephen23 le 13 Avr 2017
Note that in MATLAB [] is a concatenation operator and not a list operator, so this code:
x=['a','b','c','d','e','f']
is equivalent to this:
x = 'abcdef'
You can use a cell array or the string class to store strings as separate elements of an array.

Connectez-vous pour commenter.

Réponse acceptée

Matt Fig
Matt Fig le 24 Juin 2011
y=[1 2 3 4 5 6]
x=['a','b','c','d','e','f']
plot(y)
set(gca,'xticklabel',x.')
  2 commentaires
Hassan
Hassan le 24 Juin 2011
thanks a lot Matt.
Christine Abou Nasr
Christine Abou Nasr le 13 Avr 2017
Hello! and if I want to select just a part of the x table, how can I do? For example, I would like to plot x values 'b' to 'e'. Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by