what is wrong in this code in matlab?

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 日

0 投票

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 件のコメント

Matt Fig
Matt Fig 2011 年 4 月 14 日
Another example of the poor search capabilities on TMW website. Searching for sqrt in "latest documentation" doesn't turn up the non-symbolic form of this function in the first three pages!
Taleb Almajrbi
Taleb Almajrbi 2011 年 4 月 14 日
no, i want to use example if x=5
sqr(x)must = 25 how can i use it in matlab
Matt Fig
Matt Fig 2011 年 4 月 14 日
In that case:
sqr = @(x) x.^2; % Define this first.
sqr(5)
Taleb Almajrbi
Taleb Almajrbi 2011 年 4 月 14 日
hi Matt
so how can i use this in my code
many thanks
Matt Fig
Matt Fig 2011 年 4 月 14 日
Just like I showed you! First define the function, then use the function. Put the function definition line
sqr = @(x) x.^2; % Define this first.
anywhere in the code BEFORE you use it.
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 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by