Substituting particular matrix values
显示 更早的评论
I have four 512x512 matrices: X1a and X1b, X2a and X2b
I first want to find the coordinates in X1a and X2a where an element equals 255. For this I have been using:
[r,c,v] = find(X1a==255);
a= [r, c, v];
[r,c,v] = find(X2a==255);
b= [r, c, v];
c= [a; b];
Then I want to use ALL the coordinates that I have found (matrix c) to replace the elements in X1a AND X2a with the elements at the same coordinates from X1b and X2b respectively. However- I am unsure how to do this.
Any help would be most appreciated.
回答(1 个)
Andrei Bobrov
2014-4-22
编辑:Andrei Bobrov
2014-4-22
t1 = X1a == 255;
X1a(t1) = X1b(t1);
t2 = X2a == 255;
X2a(t2) = X2b(t2);
or
Xa = cat(3,X1a,X2a);
Xb = cat(3,X1b,X2b);
t = Xa == 255;
Xa(t) = Xb(t);
X1a = Xa(:,:,1);
X2a = Xa(:,:,2);
类别
在 帮助中心 和 File Exchange 中查找有关 Gaussian Mixture Models 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!