필터 지우기
필터 지우기

Subtracting two matrices of different size element by element

조회 수: 1 (최근 30일)
Algorithms Analyst
Algorithms Analyst 2013년 2월 21일
댓글: Image Analyst 2014년 9월 13일
Hi every one
is there any way how to subtradt two matrices of different dimension let say A=ones(40) and B=ones(12)
How can we perform subtraction like S=A-B.
Thanks

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 21일
% ----------your data-------
x=magic(4);
y=magic(2);
%-----------The code-----------
[n,m]=size(x);
[n1,m1]=size(y);
z=zeros(n,m);
z(1:n1,1:m1)=y
out=x-z
  댓글 수: 2
rana Banik
rana Banik 2014년 9월 13일
편집: Image Analyst 2014년 9월 13일
doesn't work! I have this function to perform.
distance=IMM-c;
>>whos
IMM= 132x116x2 double
c= 132x348x2 double
I have also performed bsxfun command but each time command window says error in array mismatch!!! have any other way ??
Image Analyst
Image Analyst 2014년 9월 13일
Azzi's method does not subtract the entire arrays - that is impossible. You either have to resize one of them like I suggested in my answer, or just subtract some overlapping part, like Azzi's answer which the original poster accepted. rana, for your situation you need to subtract only the first 116 columns
distance = IMM - c(:,1:size(IMM, 2), :);
It would be more robust to actually take the minimum of each dimension of the two arrays to determine the ending row, column, and third dimension.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 2월 21일
Not unless you resize one of them. But actually we'd need an actual example with actual arrays so we can understand your thought process. Please give us an example where it does exactly what you want and we can maybe tell you how to achieve that.
  댓글 수: 3
Algorithms Analyst
Algorithms Analyst 2013년 2월 21일
Actaully implementing some algorithm....so this is requirement..
Thorsten
Thorsten 2013년 2월 21일
It would be helpful if you give an example, e.g., what should be the result of
[1 2 3] - [4 5]

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by