Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Error using plot Vectors must be the same lengths when plotting thetap_dot(k) vs. time.

1 visualización (últimos 30 días)
dt= 0.001; % sampling interval [s]
N= ((T_on+T_off)/dt)+1; % how many "snapshots" in time
t= (0:dt:(N-1)*dt); % duration
xdot(1)= 2/2.23694; % initial velocity [m/s]
for k= 1:(N-1)
if xdot(k)< 10.2771045561311
thetap_dot(k)= (1/Rt)*GR*xdot(k);
xddot(k)= ((GR/Rt)*(P/thetap_dot(k)))/(M+2*It/Rt^2);
else
thetap_dot(k)= (1/Rt)*GR*xdot(k);
xddot(k)= ((GR/Rt)*(0/thetap_dot(k) ))/(M+2*It/Rt^2);
end
xdot(k+1)= xdot(k)+ xddot(k)*dt;
end

Respuestas (1)

Walter Roberson
Walter Roberson el 13 de Sept. de 2020
dt= 0.001; % sampling interval [s]
N= ((T_on+T_off)/dt)+1; % how many "snapshots" in time
N will not usually be an integer, even if T_on and T_off are integers. Remember that 0.001 is not exactly representable in binary floating point, so division by 0.001 is not the same thing as multiplication by 1000, and we as outside observers have no reason to expect that T_on and T_off are integer valued.
With N not usually being an exact integer even if 1000*(T_on+T_off) would be an integer, it becomes difficult to predict the length of
t= (0:dt:(N-1)*dt); % duration
Due to round-off in floating point calculations, this could end up one item shorter than it looks like it "should" be.
You should probably define N as an integer using round() and then use
t = (0:N-1)*dt
  3 comentarios
VBBV
VBBV el 14 de Sept. de 2020
Editada: Walter Roberson el 14 de Sept. de 2020
N = ((T_on+T_off)/dt)+1;
%if mod(N,1) ~= 0
%N = floor(N) ;
%else
% N = N;
%end
t = linspace(0,ceil((N-1)*dt),floor(N));
for k = 1:length(t)
...
end
figure (1)
plot(t,xdot*2.23694,'linewidth',2);
figure (2)
plot(t,((thetap_dot)/(2*pi/60)),'linewidth',2);
Use floor or ceil functions after checking using mod operation
Walter Roberson
Walter Roberson el 14 de Sept. de 2020
If mod(N,0) == 0 then floor(N) is the same as N, so you do not need to test with mod()

Community Treasure Hunt

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

Start Hunting!

Translated by