Effacer les filtres
Effacer les filtres

Matrix whose elements are the colums numbers

2 vues (au cours des 30 derniers jours)
Noa Prasquier
Noa Prasquier le 12 Mar 2021
Commenté : David Hill le 12 Mar 2021
Hi,
I need to create a 100*100 matrix with 3 conditions :
  • elements on the diagonal are 0
  • elements below the diagonal contain the column number
  • elements above the diagonal contain the column number with minus sign
it may look simple but I am really new here so I hope someone could help me out :)
thanks in advance

Réponses (1)

David Hill
David Hill le 12 Mar 2021
n=100;
[a,b]=ind2sub([n,n],1:n^2);
b(b==a)=0;
b(b>a)=-b(b>a);
c=reshape(b,[n,n]);
  2 commentaires
Noa Prasquier
Noa Prasquier le 12 Mar 2021
thank you so much !
David Hill
David Hill le 12 Mar 2021
If you a satisfied with the answer, you should accept it to close out the question.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by