A,B,C same size matrixes. A & C are double elements, B is with logical elements.How do I simply set A with values found in C only for true (or false) positions in B?

1 次查看(过去 30 天)
Setup:
if true
A = zeros(4,4);
C = [1,2,3,0; 5,0,6,4; 9,7,0,4; 2,0,5,6];
B = false(4,4); B(2,4) = 1; B(3,2) = 1; B(1,1) = 1;
end
How do I easily set A to copy values from C only for elements in B that are false (or true)? End result (for filtering by false value) should be: A = [0,2,3,0; 5,0,6,0; 9,0,0,4; 2,0,5,6]; Basically, we copied elements from C where B position was false/zero.
Thx

采纳的回答

Jan
Jan 2017-8-24
A = zero(size(C));
A(~B) = C(~B)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by