필터 지우기
필터 지우기

problem with Matrix Multiplication

조회 수: 1 (최근 30일)
shawin
shawin 2017년 1월 13일
답변: Are Mjaavatten 2017년 1월 13일
I have a matrix D which is 10x2, and a center Cent is 2x2 and a w diagonal matrix which is 2x2 , i have an equation:
Result = 1/W^2*(sqrt(w*(X-Y)*SIGMA^(-1)*w*(X-Y)'));
the code which i used is:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
D= [0.1 0.2 ; 0.3 0.4
0.03 0.7; 0.1 0.7
0.08 0.06; 0.04 0.9
0.11 0.13; 0.12 0.32
0.21 0.71; 1.01 0.33
];
Sigma= cov(D);
Cnt=[-1.982,1.278;0.431,-0.278]
k=2;
w=[0.6 0; 0 0.4];
Wp= 0.6^2 +0.4^2;
N=length(D);
dist=zeros(k,1);
for l=1:N
for i=1:k
dist(i) = 1/Wp*(sqrt( w*(D(l,:)-Cnt(i,:)) * inv(Sigma) * W*(D(l,:)-Cnt(i,:))'));
end
end
iam receiving error : Error using * Inner matrix dimensions must agree.
any help please

답변 (1개)

Are Mjaavatten
Are Mjaavatten 2017년 1월 13일
Note that in Matlab, vectors are matrices of column or row shape and. A 2 by 2 matrix can only be multiplied by a column vector, not by a row vector.
x = (D(l,:)-Cnt(i,:)) is a 1 by 2 matrix ( row vector)
w is a 2 by 2 matrix, so w*x will result in an error
Maybe what you want to do is to replace the content of the innermost loop by:
x = (D(l,:)-Cnt(i,:));
dist(i) = 1/Wp*(sqrt( x*W * inv(Sigma) * W'*x'));

카테고리

Help CenterFile Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by