Access difference between 3 dimensional matrices

I have two matrices,A is a 1000*1000*3 matrix and B is another matrix that started out as A and due to changes made during the code is a different 1000*10000*3 matrix. I would like to find out the position and the number of elements that have not changed. This for two D matrices can be done with setdiff, is there any way I can do this for 3D matrices? Thanks

 채택된 답변

Matt J
Matt J 2013년 6월 28일
[i,j,k] = ind2sub(size(A), find(A==B));
NumberUnchanged=length(i);

댓글 수: 4

I am a bit confused as to how this is working. For example I have a 5052*6492*3 matrix. But the NumberUnchanged returns 76827276. So I guess it is adding the unchanged values in the three dimensions? The values correspond to RGB values and my aim is to find the values that remain the same as the background that I started with.
Yep, you never mentioned anything about these being RGB images, but the modification is easy
[i,j]=find(all(A==B,3));
Sorry about not mentioning RGB! [i,j] is still a matrix bigger than my original matrix at 25609092x2 . I also tried simply find(all(A==B)),that is a 933X1 matrix. Would that give me the number of unchanged values? Or am I misunderstanding something? Thanks for commenting.
[i,j] is still a matrix bigger than my original matrix at 25609092x2
No, I don't think it's bigger
>> 5052*6492>25609092
ans =
1

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

추가 답변 (0개)

카테고리

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

제품

질문:

2013년 6월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by