matlab conditioned matrix assignment

为君一笑 提交于 2019-12-01 18:57:56

I think Dan Becker has the right idea, but re-computing abs(C-B) and abs(C-A) implies that the updated matrices are compared, not the original ones.

I don't think this is what you want, so here's the corrected version of his method:

CmA = abs(C-A);
CmB = abs(C-B);

ind = Cma < CmB; C(ind) = A(ind);
ind = CmA > CmB; C(ind) = B(ind);
C(CmA == CmB) = 0;

I think that you want the following:

ind = abs(C - A) < abs(C - B) ; C(ind) = A(ind);
ind = abs(C - A) > abs(C - B) ; C(ind) = B(ind);
ind = abs(C - A) == abs(C - B) ; C(ind) = 0;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!