DSPRelated.com
Forums

how to use functions with arguments

Started by amandeep November 10, 2009
hii
check this code....

1 function coeff_corr = correlation(i,j)
2 s1 = i - mean2(i);
3 s2 = j - mean2(j);
4 gamma_s1_s2 = sum(sum(s1.*s2));
5 gamma_s1_s1 = sum(sum(s1.*s1));
6 gamma_s2_s2 = sum(sum(s2.*s2));
7 coeff_corr = gamma_s1_s2/sqrt(gamma_s1_s1*
gamma_s2_s2);
in above code it shows following error ...please help me out
Input argument "i" is undefined.

Error in ==> correlation at 2
s1 = i - mean2(i);
regrads
aman
Amandeep,

Maybe the absence of a comma between i and j in Line 1 has MATLAB confused
about whether the argument "i" exists or not. Try

function coeff_corr = correlation(i,,j)
HTH
Sameer

On Mon, Nov 9, 2009 at 11:05 PM, amandeep wrote:

> hii
> check this code....
>
> 1 function coeff_corr = correlation(i,j)
> 2 s1 = i - mean2(i);
> 3 s2 = j - mean2(j);
> 4 gamma_s1_s2 = sum(sum(s1.*s2));
> 5 gamma_s1_s1 = sum(sum(s1.*s1));
> 6 gamma_s2_s2 = sum(sum(s2.*s2));
> 7 coeff_corr = gamma_s1_s2/sqrt(gamma_s1_s1*
> gamma_s2_s2);
>
> in above code it shows following error ...please help me out
>
> Input argument "i" is undefined.
>
> Error in ==> correlation at 2
> s1 = i - mean2(i);
>
> regrads
> aman
>
>
>

--
----
Our greatest glory consists not in never falling, but in rising every time
we fall.
-Oliver Goldsmith
Dear aman

I checked it. this code does not contain any error but for any i and j the answer is NAN !!!
I think The error that you say appeared when you run this function with "Play" button in toolbar, for run a function that you need to calling it enter this code :

for example i , j , type this code for getting answer :
coeff_corr = correlation(10,20)
regards

--- On Tue, 11/10/09, amandeep wrote:

From: amandeep
Subject: [matlab] how to use functions with arguments
To: m...
Date: Tuesday, November 10, 2009, 10:35 AM

 

hii

check this code....

1 function coeff_corr = correlation( i,j)

2 s1 = i - mean2(i);

3 s2 = j - mean2(j);

4 gamma_s1_s2 = sum(sum(s1.* s2));

5 gamma_s1_s1 = sum(sum(s1.* s1));

6 gamma_s2_s2 = sum(sum(s2.* s2));

7 coeff_corr = gamma_s1_s2/ sqrt(gamma_ s1_s1*

gamma_s2_s2) ;

in above code it shows following error ...please help me out

Input argument "i" is undefined.

Error in ==> correlation at 2

s1 = i - mean2(i);

regrads

aman
This is a function. You cannot run the file directly from it. you should define i and j first then, in command window, you can type coeff_corr = correlation( i,j). you also can used this in different program file. maybe you can check further in function help.Hope this help you.

--- On Wed, 11/11/09, Sameer Herlekar wrote:

From: Sameer Herlekar
Subject: Re: [matlab] how to use functions with arguments
To: "amandeep"
Cc: m...
Date: Wednesday, November 11, 2009, 3:49 AM

Amandeep,

Maybe the absence of a comma between i and j in Line 1 has MATLAB confused about whether the argument "i" exists or not. Try

function coeff_corr = correlation( i,,j)
HTH
Sameer

On Mon, Nov 9, 2009 at 11:05 PM, amandeep wrote:

hii

check this code....

1 function coeff_corr = correlation( i,j)

2 s1 = i - mean2(i);

3 s2 = j - mean2(j);

4 gamma_s1_s2 = sum(sum(s1.* s2));

5 gamma_s1_s1 = sum(sum(s1.* s1));

6 gamma_s2_s2 = sum(sum(s2.* s2));

7 coeff_corr = gamma_s1_s2/ sqrt(gamma_ s1_s1*

gamma_s2_s2) ;

in above code it shows following error ...please help me out

Input argument "i" is undefined.

Error in ==> correlation at 2

s1 = i - mean2(i);

regrads

aman