How can i can convert A matrix to the type i want
Mostrar comentarios más antiguos
For example i have a matrix
1 0 1 1 0
1 1 0 0 1
0 1 0 1 1
1 1 0 0 1
0 1 0 0 1
and i want when i=j that time be zero briefly i want become
0 0 1 1 0
1 0 0 0 1
0 1 0 1 1
1 1 0 0 1
0 1 0 0 0
how can i write code for it If my matrix name A
Respuesta aceptada
Más respuestas (3)
Andrei Bobrov
el 13 de Sept. de 2012
Editada: Andrei Bobrov
el 13 de Sept. de 2012
I=[1 0 1 1 0
1 1 0 0 1
0 1 0 1 1
1 1 0 0 1
0 1 0 0 1];
I(1:size(I,1)+1:end) = 0;
or
I(eye(size(I))>0) = 0;
1 comentario
Andrei Bobrov
el 13 de Sept. de 2012
if size(I,1) < size(I,2)-2
>> I = ones(4,8)
I =
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
>> I1 = I;
I1(1:size(I,1)+1:end) = 0
I1 =
0 1 1 1 1 0 1 1
1 0 1 1 1 1 0 1
1 1 0 1 1 1 1 0
1 1 1 0 1 1 1 1
>> I2 = I;
I2(eye(size(I))>0) = 0
I2 =
0 1 1 1 1 1 1 1
1 0 1 1 1 1 1 1
1 1 0 1 1 1 1 1
1 1 1 0 1 1 1 1
>>
Sean de Wolski
el 13 de Sept. de 2012
A = [1 0 1 1 0
1 1 0 0 1
0 1 0 1 1
1 1 0 0 1
0 1 0 0 1 ]
A(1:(size(A,1)+1):end) = 0
Honglei Chen
el 13 de Sept. de 2012
Editada: Honglei Chen
el 13 de Sept. de 2012
Here is another one
A.*~eye(size(A))
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!