# To select the indices of logical "1" in first 2D matrix, and then replace those corresponding indices in second 2D matrix with logical "0"

3 ビュー (過去 30 日間)
Amjad Iqbal 2022 年 3 月 18 日
コメント済み: Amjad Iqbal 2022 年 3 月 18 日
Dear Researchers and Programmers,
I have 2D matirx with logical 1, and 0. I need to select the indices having logical value 1.
Then in the second matrix, I want to replace those indices with zero.
I have attached both the matrices one is binary image and other is processed image.
Many thanks.

サインインしてコメントする。

### 採用された回答

Cris LaPierre 2022 年 3 月 18 日
Use logical indexing (Ch 11 of MATLAB Onramp)
A = randi([0 3],5)
A = 5×5
1 0 1 1 2 0 3 1 2 3 3 3 1 2 2 0 1 0 2 0 2 1 0 0 3
B = rand(5);
B(A==1) = 0
B = 5×5
0 0.5810 0 0 0.1176 0.7124 0.2019 0 0.8901 0.0881 0.5986 0.7831 0 0.6246 0.6896 0.2216 0 0.0883 0.1362 0.5453 0.9653 0 0.8447 0.6397 0.7059
##### 3 件のコメント1 件の古いコメントを表示1 件の古いコメントを非表示
Cris LaPierre 2022 年 3 月 18 日
If you are getting a logical output, you have not done what I showed. In my example, B is an array of doubles, not logicals. You use a logical array to perform the indexing (A==1). The assumption is that A and B are the same size.
Amjad Iqbal 2022 年 3 月 18 日
Yes you are right, It works now. Fantastic.
Many thanks once again.

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeImage Arithmetic についてさらに検索

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by