Replace Elements in matrix in specific positions

1 次查看(过去 30 天)
Hello, i have 3 matrixes of 15001 elements, A, B and C . What i want is that when A<=1.2 and in the same positions, -0.54<=B<=0.54, the same position D will be 0 , else inmatrix D will be = C.

回答(1 个)

goerk
goerk 2019-6-6
编辑:goerk 2019-6-6
mask = A<=1.2 && B>-0.54 && B<0.54;
D=zeros(size(C));
D(mask)=C(mask);
Edit:
Range adapted.
  2 个评论
Steven Lord
Steven Lord 2019-6-6
Replace the && in your answer with &. Use && for short-circuiting when the two expressions you're trying to and together are scalars. Use & to and together two arrays element-wise.
% Sample data
A = randn(5);
B = randn(5);
% Will throw an error
mask = A<=1.2 && B>-0.54 && B<0.54;
% Will not throw an error
mask = A<=1.2 & B>-0.54 & B<0.54;

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by