필터 지우기
필터 지우기

matrix multiplication

조회 수: 2 (최근 30일)
Fatma Gargouri
Fatma Gargouri 2011년 10월 2일
Hello,
I m wrinting a code for itertaive closest point and i got this error
??? Error using ==> mtimes
Inner matrix dimensions must agree.
RR=V * U';
V and U are two matrix in diffent size what do you think ?

채택된 답변

Wayne King
Wayne King 2011년 10월 2일
It's just telling you that the two matrices are not conformable for multiplication. The number of columns in V has to match the number of rows in U'
RR = randn(10,10)*(randn(2,10))'; % is ok
RR = randn(10,10)*(randn(10,12))'; % is not
  댓글 수: 2
Fatma Gargouri
Fatma Gargouri 2011년 10월 3일
ok so it must that the number of rows = colomns !!
and what is the diffrence between * and .* ?
Wayne King
Wayne King 2011년 10월 3일
.* is element by element multiplication so,
x = randn(10,1);
y = randn(10,1);
z = x.*y; % this is ok -- multiply x and y element by element
but
x*y % errors

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

추가 답변 (2개)

Rick Rosson
Rick Rosson 2011년 10월 2일
Please try the following:
[M,N] = size(V);
[P,Q] = size(U');
if N==P
fprintf('ok\n\n');
else
fprintf('error\n\n');
end

Rick Rosson
Rick Rosson 2011년 10월 3일
Using * by itself will perform matrix multiplication, whereas using .* will perform element-by-element multiplication.
  • For matrix multiplication, e.g. A*B, the number of columns in A must equal the number of rows in B.
  • For element-by-element multiplication, e.g. A.*B, the size and shape of both A and B must be exactly the same. In other words, if A is M x N, then B must also be M x N.
  • For more information, please see: Arithmetic Operators
  • You can use the size function to compute the size and shape of any given array.
  • You can use the assert function to test for the truth of a logical expression. For example:
assert(size(A,2) == size(B,1), ...
'The inner dimensions of A and B do not agree.');
HTH.
Rick
  댓글 수: 1
Fatma Gargouri
Fatma Gargouri 2011년 10월 3일
thank you Rick
this is very helpful
I should then review my code and verify the sizes of matrix

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

카테고리

Help CenterFile Exchange에서 Phased Array Design and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by