plot of a string vector vs numeric vector

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 件のコメント

Stephen23
Stephen23 2017 年 4 月 13 日
編集済み: Stephen23 2017 年 4 月 13 日
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.

サインインしてコメントする。

 採用された回答

Matt Fig
Matt Fig 2011 年 6 月 24 日

9 投票

y=[1 2 3 4 5 6]
x=['a','b','c','d','e','f']
plot(y)
set(gca,'xticklabel',x.')

2 件のコメント

Hassan
Hassan 2011 年 6 月 24 日
thanks a lot Matt.
Christine Abou Nasr
Christine Abou Nasr 2017 年 4 月 13 日
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!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

タグ

質問済み:

2011 年 6 月 24 日

編集済み:

2017 年 4 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by