Borrar filtros
Borrar filtros

how to check each value of matrix

1 visualización (últimos 30 días)
Offroad Jeep
Offroad Jeep el 27 de Sept. de 2015
Respondida: Stephen23 el 28 de Sept. de 2015
let
a = [1,2,3;4,5,6;7,8,9]
b = 1
c = b-a
if an element of 'a' becomes 0 after c operation it should be fixed i.e. on first operation
c = [0,1,2;3,4,5;6,7,8]
now output should be , 1 of first output should be fixed and
c = [1,2,3;4,5,6;7,8,9]
c = [1,1,2;3,4,5;6,7,8]
c = [1,1,1;2,3,4;5,6,7]
............... and so on

Respuestas (2)

Walter Roberson
Walter Roberson el 28 de Sept. de 2015
c = a;
while any(c ~= 1)
c = max(1, c-b)
end

Stephen23
Stephen23 el 28 de Sept. de 2015
Note that you can generate every output of your example in one command, where each row corresponds to one output:
>> toeplitz(ones(1,9),1:9)
ans =
1 2 3 4 5 6 7 8 9
1 1 2 3 4 5 6 7 8
1 1 1 2 3 4 5 6 7
1 1 1 1 2 3 4 5 6
1 1 1 1 1 2 3 4 5
1 1 1 1 1 1 2 3 4
1 1 1 1 1 1 1 2 3
1 1 1 1 1 1 1 1 2
1 1 1 1 1 1 1 1 1

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by