plot two vectors simultaneuosly on the same axis?

Regards. I have 2 vectors. For example a=[2 4 3 6 7 8] and b=[7 5 2 4 4 1]. I wolud like to plot them both on x axis simultaneously, for exampe in order a=2,b=7,a=4,b=5... y axis is supposed to be 0 for vector a and 1 for vector b. is this possible to do? Thank you.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 28일

1 개 추천

a=[2 4 3 6 7 8]
b=[7 5 2 4 4 1]
x=[a ;b]
x=x(:)
y=[zeros(size(a)); ones(size(b))]
y=y(:)
plot(x,y)

댓글 수: 4

Bojan
Bojan 2014년 3월 28일
THANK YOU VERY MUCH Azzi ! This is what I was looking for ! You saved me ! Best regards!
Bojan
Bojan 2014년 3월 28일
편집: Bojan 2014년 3월 28일
just a question, this plot of yours is in order 2,1,2,1.... not in order 2,7,4,5...... as it is supposed to be from matrix. do you have solution for that?
The order is not 2 1 2 1, you can check by
disp(x)
Maybe you mean something else
Bojan
Bojan 2014년 3월 28일
Jes, sorry. This is disp(x) 2 4 3 6 7 8 7 5 2 4 4 1
for me it should be 2 7 4 5 3 2 6 4 7 4 8 1
first value of vector a, then first value of vector b, then second value of vector a ..... and so on
and x axis is supposed to be long as sum of all values in both vector: 2+7+4+5+3+2+6+4+7+4+8+1 =53 cca

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Chandrasekhar
Chandrasekhar 2014년 3월 28일
편집: Chandrasekhar 2014년 3월 28일

3 개 추천

plot(a)
hold
plot(b)

댓글 수: 1

Bojan
Bojan 2014년 3월 28일
that is not what I am looking for. You should read better. Thanks anyway. Regards

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

태그

질문:

2014년 3월 28일

댓글:

2014년 3월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by