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.
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 Exchange에서 Characters 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