I am trying to plot the magnitude of velocity and position against time but keep running into issues.(adsbygoogle = window.adsbygoogle || []).push({});

The error I am getting here is:

Subscript indices must either be real positive integers or logicals.

Error in project2 (line 46)

position(t) = w(1:3);

Here is the relevant portion of my script(everything else work fine except the plot):

N = 540;

a = 1;

b = 5400;

h = (b-a)/N;

t = a;

w = [r(1);r(2);r(3);v(1);v(2);v(3)];

for t = 1:10:5400

k1 = h*rky(t,w);

k2 = h*rky(t+h/2,w+k1/2);

k3 = h*rky(t+h/2,w+k2/2);

k4 = h*rky(t+h,w+k3);

w = w + (h/6)*(k1+2*k2+2*k3+k4);

t = t+h;

position(t) = w(1:3);

velocity(t) = w(4:6);

time(t) = t;

end

subplot(2,1,1),plot(time,norm(position))

title('position');

xlabel('Time');

ylabel('Displacement');

axis([1 5400 0 10000]);

subplot(2,1,2),plot(time,norm(velocity))

title('velocity');

xlabel('Time');

ylabel('Displacement');

axis([1 5400 0 5]);

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# MATLAB plotting issue

Tags:

Loading...

Similar Threads - MATLAB plotting issue | Date |
---|---|

Matlab Plotting Coordinate Transformations in Matlab | Feb 12, 2018 |

Matlab Plotting animations (time-evolution) | Jan 17, 2018 |

Does anyone had this plotting problem with MATLAB? | Dec 23, 2017 |

Matlab Matlab's plot command | Nov 30, 2017 |

Matlab Matlab -- how to make a smooth contour plot? | Jun 28, 2017 |

**Physics Forums - The Fusion of Science and Community**