using FIND in 3D matrix

조회 수: 2 (최근 30일)
xplore29
xplore29 2013년 5월 29일
I am trying to find the 3rd dimension index value for the following case
A(:,:,1)=[1 2 ; 3 4]
A(:,:,2)=[9 8 ; 4 4]
A(:,:,3)=[2 4 ; 7 4]
B=[1 2 ; 3 4]
How can I use find(.) for this purpose

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 29일
idx=find(arrayfun(@(x) isequal(A(:,:,x),B),1:size(A,3)))

추가 답변 (2개)

Sean de Wolski
Sean de Wolski 2013년 5월 29일
I would do that like this:
A(:,:,1)=[1 2 ; 3 4];
A(:,:,2)=[9 8 ; 4 4];
A(:,:,3)=[2 4 ; 7 4];
A(:,:,4)=A(:,:,1);
B=[1 2 ; 3 4];
idx = find(all(all(bsxfun(@eq,A,B),1),2))
Find where all elements in rows/cols are equal in pages
  댓글 수: 2
xplore29
xplore29 2013년 5월 29일
I didnt understand why would you declare A(:,:,4)=A(:,:,1).
Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 29일
It's just an example to test the code

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


Andrei Bobrov
Andrei Bobrov 2013년 5월 29일
[ii,jj]=ismember(reshape(A,[],size(A,3))',B(:)','rows');
out = jj(ii);

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by