Clear Filters
Clear Filters

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

2 views (last 30 days)
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 Comments
Stephen23
Stephen23 on 26 Mar 2020
Edited: Stephen23 on 27 Mar 2020
"...wtihout assigning 3 channels separetely"
Assigning the three columns separately is probably the simplest and most efficient way.
Baris Kiliclar
Baris Kiliclar on 27 Mar 2020
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

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!