Borrar filtros
Borrar filtros

Repeating elements in a matrix.

1 visualización (últimos 30 días)
Gratitude Kim
Gratitude Kim el 27 de Jul. de 2017
Comentada: Gratitude Kim el 27 de Jul. de 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

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 27 de Jul. de 2017
Editada: Andrei Bobrov el 27 de Jul. de 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);

Más respuestas (0)

Categorías

Más información sobre Power and Energy Systems en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by