Filter löschen
Filter löschen

repeat in the same vector

1 Ansicht (letzte 30 Tage)
Marco Carapellese
Marco Carapellese am 3 Mär. 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

Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Descriptive Statistics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by