How to cycle through a vector to create a matrix?
Show older comments
A=[a,b,c,d,0,0,0,0...,0] 1xN vector
Using vector "A", I want to create an NxN matrix such that each row is the previous row with its elements fliped one at a time. That is, I want to create:
[a,b,c,d,0,0,0,...,0;
0,a,b,c,d,0,0,,...0;
0,0,a,b,c,d,0,...0;
.....
0,...0,0,0,a,b,c,d]
I could use a "for statement" using A=[A(end), A(1:end-1)] and vertcat(). But is there a more efficient and elegant way of doing this? Thanks
Accepted Answer
More Answers (0)
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!