Azzera filtri
Azzera filtri

Repeating elements in a matrix.

1 visualizzazione (ultimi 30 giorni)
Gratitude Kim
Gratitude Kim il 27 Lug 2017
Commentato: Gratitude Kim il 27 Lug 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

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 27 Lug 2017
Modificato: Andrei Bobrov il 27 Lug 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);

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by