Subtracting Two Matrices of different sizes

조회 수: 11 (최근 30일)
AR
AR 2015년 12월 18일
댓글: AR 2015년 12월 20일
How do I do the following subtraction: let X = [302 64] where all values in X are either 0s or 1s
A= X - X';
A=[302 64] - [64 302];
How do I find subtract these?
  댓글 수: 3
AR
AR 2015년 12월 18일
Walter, Was expecting [302 302]; additionally I'm subtracting [302 64] - [64 140] and would like this to equal [302 140]. Hope this is possible as I'm stuck with many errors in do loop. Thx, Allen
Walter Roberson
Walter Roberson 2015년 12월 18일
For any one entry in the result, say A(J,K), how should A(J,K) be computed?

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

채택된 답변

Walter Roberson
Walter Roberson 2015년 12월 18일
T1 = X; %the left side
T2 = X'; %whatever the right side is
if any(size(T1) < size(T2))
T1(size(T2,1),size(T2,2)) = 0; %zero pad
end
if any(size(T2) < size(T1))
T2(size(T1,1),size(T1,2)) = 0; %zero pad
end
A = T1 - T2;

추가 답변 (1개)

Renato Agurto
Renato Agurto 2015년 12월 18일
Hi
do you mean something like this?
%A,B: inputs matrices
%C output matrix
N = max([size(A,1) size(B,1)]);
M = max([size(A,2) size(B,2)]);
An = zeros(N,M);
Bn = zeros(N,M);
An(1:size(A,1), 1:1:size(A,2)) = A;
Bn(1:size(B,1), 1:1:size(B,2)) = B;
C = An-Bn
  댓글 수: 1
AR
AR 2015년 12월 20일
Renato, Thanks. This way worked too. Allen

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by