Replace Elements in matrix in specific positions

6 ビュー (過去 30 日間)
Pedro R
Pedro R 2019 年 6 月 6 日
コメント済み: Steven Lord 2019 年 6 月 6 日
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 件のコメント
madhan ravi
madhan ravi 2019 年 6 月 6 日
Pedro R commented:
sorry, is was -0.54.
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 Center および File ExchangeData Type Identification についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by