How to apply logical matrix to the matrix with array operation?

33 ビュー (過去 30 日間)
Qingyuan Li
Qingyuan Li 2021 年 9 月 23 日
編集済み: Matt J 2021 年 9 月 23 日
I was wonder that once i create a mask from the image, is there any way that i can ask the matlab to generate the matrix of image based on the logical value from the mask. In orther words, if i have a mask that labels the ball, how can i apply the mask to the image to only shows the pixels of ball.
I am mainly looking for array operation since for loop that iterate through height and length is quit slow.
Lets take a look on a example in 2D matrix.
Matrix = [ 3 4;
5 6]
Logical= [ 1 1 ;
0 0]
I want to have a result:
R = [3 4;
0 0]
Thank you in advance!

採用された回答

Matt J
Matt J 2021 年 9 月 23 日
編集済み: Matt J 2021 年 9 月 23 日
Matrix = [ 3 4;
5 6];
Logical= [ 1 1 ;
0 0];
R=Logical.*Matrix
R = 2×2
3 4 0 0

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by