plotting two-vectors on same axis
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Raghavendra Reddy P
el 1 de Jun. de 2015
Comentada: Raghavendra Reddy P
el 1 de Jun. de 2015
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.
0 comentarios
Respuesta aceptada
Walter Roberson
el 1 de Jun. de 2015
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Discrete Data Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!