I have any matrix and a scalar from which i want to alter this matrix consisting of only those numbers which are divisible by scalar only

If A is your matrix and n is your scalar:

A = magic(5);

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;

Browse More Popular Posts

Leave a Comment