Find elements from a submatrix in the main 3D matrix

Hello.
I have a matrix M = 10x5. 10 representing the number of users and 5 the values for each user. This is taken out of the bigger matrix A = 161x161x10. 10 again being the same number of users as in the M matrix. The values from M are in A.
My main goal is to find the indexes (or ROW,COL) from the values from matrix M in matrix A. The problem is that because in M , I have duplicate values I can't find use the FIND function. Based on my research I did not found something helpful.
Do you think is possible to do this? Thank you!

 채택된 답변

Matt J
Matt J 2021년 7월 20일
[row,col]=find( reshape( ismember(M(:),A(:)) , size(M) ) );

댓글 수: 6

Still not working for the duplicate values :(
Let's do a small example. The results below look correct to me, even though there are clearly duplicates in M.
M=randi(3,2)
M = 2×2
2 3 3 3
A=randi(3,5,5,2)
A =
A(:,:,1) = 1 2 1 3 1 2 1 2 3 2 3 2 2 2 3 1 1 3 1 1 2 1 2 1 1 A(:,:,2) = 3 3 2 1 1 1 1 2 3 1 1 1 3 3 2 2 3 2 3 1 1 3 1 1 3
[row,col]=find( reshape( ismember(M(:),A(:)) , size(M) ) )
row = 4×1
1 2 1 2
col = 4×1
1 1 2 2
Bianca Brisc
Bianca Brisc 2021년 7월 20일
편집: Bianca Brisc 2021년 7월 20일
I am sorry I don't understand your results. I want the indexes of the values from M in the matrix A.
So if I have the value 2 in matrix M the first index of it in matrix A will be row-1 col-2. The second will be row-2 col-1 and so on. (for A(:,:,1))
Maybe my explaining was bad in the first place.
Sorry.
Thank you!
Perhaps as follows, then?
for i=1:10
[row{i},col{i}]=find( ismember(A(:,:,i),M(i,:)) );
end
@Matt J Thank you very much! I could not make it work with row and col but I am finding the indexes and then I will convert into row and column. The only problem is when the indexes are added to the cell they are added in ascending order which for my case is not the ideal case but I think I can sort it out somehow.
Thank you for the answers. If you have any more suggestions, I am happy to read them!
You're welcome, but please Accept-click the answer if you have what you need.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 7월 20일

댓글:

2021년 7월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by