repeat in the same vector

2 次查看(过去 30 天)
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

回答(1 个)

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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by