필터 지우기
필터 지우기

How can i index lower dimensions of a matrix by another matrix of lower dimension?

조회 수: 2 (최근 30일)
Hello guys,
I want to index lower dimensions by a logical matrix for example:
A is m by n by 3 array. (uint8 RGB image )
B= m by n logic array. Following assignment doesn't work.
A(B,:)=0 ;
How can i do that in the simplest way ? (wtihout assigning 3 channels separetely)
Thanks,
Barış Kılıçlar
  댓글 수: 2
Stephen23
Stephen23 2020년 3월 26일
편집: Stephen23 2020년 3월 27일
"...wtihout assigning 3 channels separetely"
Assigning the three columns separately is probably the simplest and most efficient way.
Baris Kiliclar
Baris Kiliclar 2020년 3월 27일
From "...wtihout assigning 3 channels separetely" , i just want to avoid the following sequence:
Ar=A(:,:,1);
Ag=A(:,:,2);
Ab=A(:,:,3);
Ar(B)=0;
Ag(B)=0;
Ab(B)=0;
C=cat(3,Ar,Ag,Ab);
which is very long, inefficient and boring.
But, your suggestion at somewhere in the post you gave the link above: (translated to the terms in this post)
A(B(:,:,[1,1,1]))=0;
is quite satisfactory and elegant for my actual needs.
Thank you very much.
Barış Kılıçlar

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by