N = 5;
Nt = length(t);
xe = zeros(N, Nt);
xe(1,:) = (-lm/2)+Vest*t;
for K = 1 : N
idx = xe(K,:) > 2*lm;
xe(K,idx) = -lm/2;
if K ~= N
xe(K+1,:) = xe(K,:) + lm/4;
end
end
plot(xe.'); %if you want N lines
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!