plot of a string vector vs numeric vector

19 Ansichten (letzte 30 Tage)
Hassan
Hassan am 24 Jun. 2011
Bearbeitet: Stephen23 am 13 Apr. 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 Kommentar
Stephen23
Stephen23 am 13 Apr. 2017
Bearbeitet: Stephen23 am 13 Apr. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt Fig
Matt Fig am 24 Jun. 2011
y=[1 2 3 4 5 6]
x=['a','b','c','d','e','f']
plot(y)
set(gca,'xticklabel',x.')
  2 Kommentare
Hassan
Hassan am 24 Jun. 2011
thanks a lot Matt.
Christine Abou Nasr
Christine Abou Nasr am 13 Apr. 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!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by