Effacer les filtres
Effacer les filtres

Repeating elements in a matrix.

1 vue (au cours des 30 derniers jours)
Gratitude Kim
Gratitude Kim le 27 Juil 2017
Commenté : Gratitude Kim le 27 Juil 2017
A=zeros(3,4)
A =
0 0 0 0
0 0 0 0
0 0 0 0
>> [nRows,nCols] = size(A); A(1:(nRows+1):nRows*nCols) = 1
A =
1 0 0 0
0 1 0 0
0 0 1 0
Appreciate your kind assistance on how can I write so that my matrix becomes :
A=[1 1 0 0; 0 1 1 0; 0 0 1 1]
Thanks

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 27 Juil 2017
Modifié(e) : Andrei Bobrov le 27 Juil 2017
A=zeros(3,4);
n = size(A,1);
A([1:n+1:end,n+1:n+1:end]) = 1
or
t = true(3,4);
out = tril(t,1) & triu(t);
  1 commentaire
Gratitude Kim
Gratitude Kim le 27 Juil 2017
Noted with thanks. =)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Power and Energy Systems dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by