how to check each value of matrix

1 vue (au cours des 30 derniers jours)
Offroad Jeep
Offroad Jeep le 27 Sep 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

Réponses (2)

Walter Roberson
Walter Roberson le 28 Sep 2015
c = a;
while any(c ~= 1)
c = max(1, c-b)
end

Stephen23
Stephen23 le 28 Sep 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

Catégories

En savoir plus sur Entering Commands dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by