Azzera filtri
Azzera filtri

repeat in the same vector

2 visualizzazioni (ultimi 30 giorni)
Marco Carapellese
Marco Carapellese il 3 Mar 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

Risposte (1)

KSSV
KSSV il 3 Mar 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 Commento
Marco Carapellese
Marco Carapellese il 3 Mar 2022
thanks for the answer, but I have modified the question to add further problems, as that mode is not usable in my case

Accedi per commentare.

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by