Adding columns to matrix using circshift by auto incrementing
Afficher commentaires plus anciens
I want to develop a square matrix from a column matrix using circshift. Here is an example code:
z=[0;1;2;3];
x=[z,circshift(z,1),circshift(z,2),circshift(z,3)];
Output: >> x
x =
0 3 2 1
1 0 3 2
2 1 0 3
3 2 1 0
I have to do similar for the order of 1200 instead of 4 so I want it to be automatic. Can some one please suggest how can I use loop of vector in this case?
Thanks
Réponse acceptée
Plus de réponses (2)
Andrei Bobrov
le 4 Fév 2014
z=[0;1;2;3];
x = [z;z];
n = numel(z);
out = x(bsxfun(@minus,(n+1:2*n)',0:n-1));
saad
le 4 Fév 2014
0 votes
Catégories
En savoir plus sur Sparse Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!