Hi all,
How do I make this matrix in Matlab?
Thanks

1 commentaire

Image Analyst
Image Analyst le 28 Nov 2011
Fast comment - what number should be in the blank areas?

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 28 Nov 2011

0 votes

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 commentaire

Walter Roberson
Walter Roberson le 28 Nov 2011
There are faster ways using ordinary assignments.

Connectez-vous pour commenter.

Plus de réponses (0)

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!

Translated by