How do I offset a vector plot?

14 visualizaciones (últimos 30 días)
Kevin Shen
Kevin Shen el 6 de Ag. de 2020
Comentada: Fangjun Jiang el 6 de Ag. de 2020
Hello there!
I have this bit of code below. I want it to plot points like (5,5) (6,7)(7,9)(8,11)(9,13), etc. Basically, the x being the corresponding place in the vector, and teh y being the value of the vector. Currently, I get (1,5) (2,7) (3,9) because its the length of the vector not the actual "length" number. How would I do that? (If I am not clear please tell me)
V = 5:2:17
figure
plot(1:length(V),V)

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 6 de Ag. de 2020
V = 5:2:17;
index=5:9;
figure
plot(index,V(index))
  2 comentarios
Kevin Shen
Kevin Shen el 6 de Ag. de 2020
Thanks for replying, however, when I run the code, its says
Index exceeds the number of array elements (7).
Error in TESTGRAF (line 4)
plot(index,V(index))
Also, here is the complete list of what I want to graph
(5,5) (6,7) (7,9) (8,11) (9,13) (10,15) (11, 17), if this changes the answer.
Thanks!
Fangjun Jiang
Fangjun Jiang el 6 de Ag. de 2020
Apparently I didn't run the code myself. The error says V has only 7 elements while the index tries to pick the 9th element.
This should be the code if value 5 is the 5th element of your V
%%
V = -3:2:50;
index=5:11;
figure
plot(index,V(index))

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D 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!

Translated by