what is wrong in this code in matlab?

조회 수: 3 (최근 30일)
Taleb Almajrbi
Taleb Almajrbi 2011년 4월 14일
hi can you tell me what is wrong in this code becouse o got wrong message which is (??? Undefined function or method 'sqr' for input arguments of type 'double')
for (c1=sqr(features1(:,j)- mean_of_column1); and
p1=0;
p2=0;
for j=1:c
c1=sqr(features1(:,j)- mean_of_column1);
c2=sqr(features2(:,j)- mean_of_column2);
p1=p1+c1;
p2=p2+c2;
end;
denominator=sqrt(p1)* sqrt(p2);
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 4월 14일
'and' is not valid at that position in the code.

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

채택된 답변

Matt Fig
Matt Fig 2011년 4월 14일
You probably mean to use the SQRT function to find the square root.
In response to your clarifying comment,
sqr = @(x) x.^2; % Define this first, before you use it!
sqr(5)
  댓글 수: 7
Taleb Almajrbi
Taleb Almajrbi 2011년 4월 14일
hi matt
i got another wrong message which is (??? Error using ==> mtimes
Inner matrix dimensions must agree.) for denominator=sqrt(p1)* sqrt(p2); in the same code.
can you solve it to me?
thanks
Matt Fig
Matt Fig 2011년 4월 14일
Yes, whenever you are working with arrays and need to do element by element multiplication, use this instead:
sqrt(p1).* sqrt(p2); % Notice the .* instead of * only.
The same goes for / and ^.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by