Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
Stephen23
Stephen23 il 26 Mar 2020
Modificato: Stephen23 il 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 il 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

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by