How to create a sqaure matrix from a one dimensional vector

Hi all,
I want to create a n*n matric from a 1*n matrix such that all possible every column is the shifted version of the previous one. For example, 1 2 3 4 then matrix should look like
1 2 3 4
2 3 4 1
3 4 1 2
4 1 2 3
Thanks

 채택된 답변

Sean de Wolski
Sean de Wolski 2012년 3월 1일
x = 1:4;
gallery('circul',x) %gallery strikes again!
More
fliplr(gallery('circul',fliplr(x)))
since you want it shifted to the left.

추가 답변 (1개)

Wayne King
Wayne King 2012년 3월 1일
One way:
x = [1 2 3 4];
x = x(:);
x = repmat(x,1,4);
for nn = 2:4
x(:,nn) = circshift(x(:,nn),nn-1);
end

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by