Matrix manipulation
이전 댓글 표시
Hi I'm new to Matlab and seem to be struggling again. I'm trying to subtract corresponding elements from two image matrices i.e.
matrix 1= A B matrix 2= a b C D c d
I'm trying to get (A-a)^2+(B-b)^2.....
Thanks in advance for any help, it;s really appreciated.
답변 (4개)
the cyclist
2011년 3월 25일
Not 100% if this is what you mean, but ...
M1 = [1 2 3 4];
M2 = [5 6 7 8];
M3 = (M1-M2).^2;
댓글 수: 5
Karen Rafferty
2011년 3월 25일
Matt Fig
2011년 3월 25일
No FOR loop is needed.
M3 = sum((M1-M2).^2)
If you expect a scalar from the operation, do this:
M3 = sum((M1(:)-M2(:)).^2)
Karen Rafferty
2011년 3월 25일
Matt Fig
2011년 3월 25일
Yes, what version are you using, because this works find on my system.
Try this:
sum((Groundtruth-double(Haarbk2)).^2)
Karen Rafferty
2011년 3월 25일
Sean de Wolski
2011년 3월 25일
M3 = sum((Groundtruth(:)-double(Haarbk2(:))).^2);
Karen Rafferty
2011년 3월 25일
0 개 추천
댓글 수: 3
Matt Fig
2011년 3월 25일
So what does this return:
class(Groundtruth)
class(Haarbk2)
Karen Rafferty
2011년 3월 25일
Sean de Wolski
2011년 3월 25일
Yes. You can't have a negative unsigned integer.
Haarbk2 = double(Haarbk2);
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!