If A
is your matrix and n
is your scalar:
A = magic(5);
n=2;
Then to manipulate (e.g. multiply by 1000
) the elements of A
that are divisible by n
, just do:
idx = mod(A,n)==0;
A(idx) = A(idx)*1000;
If A
is your matrix and n
is your scalar:
A = magic(5);
n=2;
Then to manipulate (e.g. multiply by 1000
) the elements of A
that are divisible by n
, just do:
idx = mod(A,n)==0;
A(idx) = A(idx)*1000;