Fast question!

5 views (last 30 days)
Feruz
Feruz on 28 Nov 2011
Hi all,
How do I make this matrix in Matlab?
Thanks
  1 Comment
Image Analyst
Image Analyst on 28 Nov 2011
Fast comment - what number should be in the blank areas?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 28 Nov 2011
If the output matrix is to be n by n, then
M = diag(ones(m-1,1),1) + diag(-ones(m-1,1),-1) + diag(1,1-n) + diag(1,n-1);
  1 Comment
Walter Roberson
Walter Roberson on 28 Nov 2011
There are faster ways using ordinary assignments.

Sign in to comment.

More Answers (0)

Categories

Find more on Sparse 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!