Elmo HARSFEN0602, HARmonica software manual Automatic variables, Std, Mean

Models: HARmonica HARSFEN0602

1 220
Download 220 pages 51.63 Kb
Page 45
Image 45

HARSFEN0602ElmoHARmonicaSoftwareManual

PRELIMINARYDRAFT

If some function does not return any output by its definition, then zero value as output will be inserted to the stack actually. Assume that the function foo is declared with no output arguments. So the following expression:

foo () + 3 is legal, because foo returns zero by default.

Example:

43

float vec[11], RA[100];

Declare the global variables

float value;

Declare the global variable

function [float mean, float std]=statistic();

Prototype of the function

...

 

[RA[1],RA[2]]=statistic()

Calling the STATISTIC function. After

 

executing RA[1] will be equal to variable

 

MEAN and RA[2] will be equal to variable

 

STD

[value]= statistic()

In this case, after executing the STATISTIC

 

function VALUE will be equal to variable

 

MEAN

 

function [float mean, float std]=statistic()

Declaration of a function that calculates mean

 

and standard deviation of the global vector

 

vec.

int k;

Declare k as automatic variable

global vec[11];

Redeclaration for vec variable (vec is the

 

global variable that is declared before)

mean=0;

 

for k = 1:10

 

mean = mean + vec[k];

 

end

 

mean = mean/10;

Calculate mean of vec[]

if ( nargout > 1)

Only if the standard deviation is asked...

std = 0 ;

 

for k =1:10

 

std = std + vec[k] * vec[k] ;

 

end

 

st = (1/10)* sqrt( std – 10 * sum)

 

end

 

return

End of the function body

 

 

 

Count of input arguments

The number of input arguments during function call must be the same as it is declared during function definition.

5.6.4Automatic variables

A variable declared within a function is automatic. It is generated when the function is called, and it ceases to exist when the function exits.

At the time of function call, all its automatic variables are set to zero. When the function

Page 45
Image 45
Elmo HARSFEN0602, HARmonica software manual Automatic variables, Std, Mean