using FIND in 3D matrix

1 次查看(过去 30 天)
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 中查找有关 Data Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by