how to check each value of matrix

조회 수: 2 (최근 30일)
Offroad Jeep
Offroad Jeep 2015년 9월 27일
답변: Stephen23 2015년 9월 28일
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

답변 (2개)

Walter Roberson
Walter Roberson 2015년 9월 28일
c = a;
while any(c ~= 1)
c = max(1, c-b)
end

Stephen23
Stephen23 2015년 9월 28일
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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by