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 个评论
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