Borrar filtros
Borrar filtros

repeat in the same vector

1 visualización (últimos 30 días)
Marco Carapellese
Marco Carapellese el 3 de Mzo. de 2022
Comentada: Marco Carapellese el 3 de Mzo. de 2022
hi to all I have a vector [1 2 3; 4 5 6] I would like to repeat the elements within another vector n times. For example, if n = 2 I would like to obtain [1 2 3 1 2 3; 4 5 6 4 5 6]. How can I do? Thank you
specifically I have this vector ripetuta(f,:, v) which I would like to construct as the vector newgreentime (:,:, v) to be repeated on lines as many times as repetizioni(f, 1, v) = floor (T / sommetime (f, end, v)) ;. The values ​​for each row of repetitions are different from each other. It's possible to do it?
for i = 1:duration
traci.simulation.step();
for n = 1: length(inductionID)
veicoliOGNIISTANTEsuInduction(n,i)=traci.inductionloop.getLastStepVehicleNumber(inductionID{n});
end
for v=1:length(k)
if i==t(v)
for n = 1: length(inductionID)
veicoliT(n,v)=sum(veicoliOGNIISTANTEsuInduction(n,(t(v)-(T-1)):t(v)));
end
for f=1:length(semaforiID)
% here begins the part of interest
newgreentime(:,:,v)=reshape(-L*veicoliT(:,v), 2,2)';
ripetizioni(f,1,v)=floor(T/sommetime(f,end,v)); % T is 90
ripetuta(:,:,v)= % i tried with a solution like ma non funziona repmat(newgreentime(f,:,v),1,ripetizioni(f,1,v));
end
end
end
end

Respuestas (1)

KSSV
KSSV el 3 de Mzo. de 2022
v = [1 2 3; 4 5 6] ;
iwant = repmat(v,1,2)
iwant = 2×6
1 2 3 1 2 3 4 5 6 4 5 6
  1 comentario
Marco Carapellese
Marco Carapellese el 3 de Mzo. de 2022
thanks for the answer, but I have modified the question to add further problems, as that mode is not usable in my case

Iniciar sesión para comentar.

Categorías

Más información sobre Descriptive Statistics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by