plotting two-vectors on same axis

조회 수: 1 (최근 30일)
Raghavendra Reddy P
Raghavendra Reddy P 2015년 6월 1일
댓글: Raghavendra Reddy P 2015년 6월 1일
I have vector x contains 33-elements
x = [
1.0000
0.9974
0.9853
0.9793
0.9735
0.9588
0.9560
0.9461
0.9421
0.9385
0.9380
0.9372
0.9343
0.9333
0.9319
0.9306
0.9286
0.9280
0.9969
0.9933
0.9926
0.9920
0.9817
0.9751
0.9718
0.9572
0.9552
0.9462
0.9397
0.9362
0.9321
0.9291
0.9288]
>> t=[1:33];
>> plot(t,x)
gives you a graph, now i have a y vector which contains only 13 elements
y = [
1.0000
0.9974
0.9853
0.9712
0.9588
0.9360
0.9333
0.9295
0.9928
0.9763
0.9483
0.9397
0.9279]
now i wanted to draw graph on existing one such that elements values of y, which are near to x values should come same t-axis points. example:- y(4)=0.9712 is almost equal equal to x(5)=0.9735 at t=5, y(end)=0.9279 is equal to x(end)=0.9288 at t=33... hence i want y(4),y(end) on t=5,t=33.

채택된 답변

Walter Roberson
Walter Roberson 2015년 6월 1일
y(end)=0.9279 is equal to x(end)=0.9288 at t=33
0.9729 is smaller than any x value, and is closest to x(18) which is 0.9280.
y(4)=0.9712 is almost equal equal to x(5)=0.9735 at t=5
0.9712 is closer to x(25) = 0.9718
The descriptive part about "near to x values" leads to this code:
plot(1:length(x),x,'r',interp1(x, 1:length(x), y, 'nearest', 'extrap'),y,'g.-')
which has each y value being drawn at the t value that corresponds to the x value that is closest to the y value.
Your rules about what is near enough do not appear to be well defined.
  댓글 수: 1
Raghavendra Reddy P
Raghavendra Reddy P 2015년 6월 1일
Thank you sir, since the above values are small fraction numbers i couldn't differentiate exactly the way i wanted. your coding is fine. i just wanted to draw y graph on same x-axis of x graph such that elements values of y and x are closer.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by