[英]MATLAB Changing matrix elements
How can I iterate over matrix and change values under condition.. for eg: I have matrix m with size 100x100 and Im doing: 我如何在条件下迭代矩阵并更改值。例如:我有矩阵m的大小为100x100,Im在做:
m(m<10)=func(elemnt);
element should be the current element at iteration.. How do I access the current element?? 元素应该是迭代时的当前元素。如何访问当前元素?
Try simply m(m<10)=func(m(m<10));
简单尝试
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. 唯一的限制是您的自定义函数可以处理向量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.