How to create a sqaure matrix from a one dimensional vector
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Hypothesis Tests 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!