# How to find the indices within a matrix where its elements are identical along the third dimension

1 ビュー (過去 30 日間)
KostasK 2021 年 2 月 3 日
コメント済み: KostasK 2021 年 2 月 4 日
Hi all,
I am scratching my head to determine a way where I can find the indices within a multi-dimensional matrix where its elements are identical (i.e. equal) along the third dimension.
In specific I have a multi-dimensional matrix:
M = rand(100,100,3) ;
Lets say somewhere in that matrix, along the third dimension we have some elements that are equal, which we would be able to identify with the following way.
idx = M(:,:,1) == M(:,:,2) & M(:,:,2) == M(:,:,3) ;
Admitedly, the above would give me what I want but when the third dimension becomes much greater than 3 (as it does in my case), it becomes quite cumbersome to code. I would therefore appreciate your help with this.
Regards
KMT.

サインインしてコメントする。

### 採用された回答

Matt J 2021 年 2 月 3 日

idx = all( M==M(:,:,1) , 3);
##### 1 件のコメント表示非表示 なし
KostasK 2021 年 2 月 4 日
Nice one!

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!

Translated by