Vectorization with a loop and repmat
Mostra commenti meno recenti
i would like to vectoralize the following codes with loop;
n=5;
k=3;
x=(k:n)';
m=[];
for i = 1 : (n-k+1)
m=[m,x];
x=circshift(x,-1);
end
example;
k=3, n=5
3 4 5,
4 5 3,
5 3 4
please help me out
Risposta accettata
Più risposte (2)
Azzi Abdelmalek
il 14 Ago 2014
Modificato: Azzi Abdelmalek
il 14 Ago 2014
n=5;
k=3;
x=(k:n)'
idx=rem(bsxfun(@plus,(0:n-k)',(0:n-k)),n-k+1)+1
out=x(idx)
Matt J
il 14 Ago 2014
y=k:n-1;
m = fliplr(toeplitz([n,y],[n,fliplr(y)]))
Categorie
Scopri di più su Just for fun in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!