Reputation: 2746
How can I iterate over matrix and change values under condition.. for e.g: I have matrix m with size 100x100 and Im doing:
m(m<10)=func(elemnt);
element should be the current element at iteration.. How do I access the current element??
Upvotes: 0
Views: 1068
Reputation: 20017
Try simply
m(m<10)=func(m(m<10));
example:
m=[[1 2 3];[5 6 7];[8 9 10]]
m =
1 2 3
5 6 7
8 9 10
m(mod(m,3)==2) = m(mod(m,3)==2) * 5
m =
1 10 3
25 6 7
40 9 10
The only constraint is that your custom function can handle vectors.
Upvotes: 3