Info

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

Impose to a vector not to have zero elements

1 visualización (últimos 30 días)
Federico Ferrara
Federico Ferrara el 18 de Sept. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi everybody I need an help. Actually I've got a problem with my matlab code. The code is quite long and complex and deals with autonomous driving. I made a control system such that a leader vehicle tells to other vechicles behind to follow it. Now, i would like that, given an acceleration law, my vector that contains the speed does not become zero, or lower, in case of a high deceleration. How can I perform this?
speed=zeros(N,size(sol.y,2));
speed(1,:)=sol.y(N+1,:);
speed(2,:)=sol.y(N+1,:)-sol.y(N+2,:);
for n=3:N
speed(n,:)=sol.y(N+1,:)-sum(sol.y(N+2:N+n,:),1);
end
that is how my speed vector, for each vehicle is filled up...But, regardless from this, how can I say to matlab "if speed <=0 then speed=0?
thanks

Respuestas (1)

Dana
Dana el 18 de Sept. de 2020
speed(n,:)=max(sol.y(N+1,:)-sum(sol.y(N+2:N+n,:),1), 0);

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by