Functions Flashcards
Returning variables in a function
Function x=’function name’
//commands to execute
End
Where x is the variable in the function
Returning multiple variables in a function
Function [x y z …] = ‘function name’
//commands to execute
End
How to pass a variable(s) to functions from the command line
Function x=’function name’(y,z,a,b,…)
//commands to execute
End
Where y,z,a,b are variables that are passed to the function
Structure of a function in MATLAB
Function ‘function name’
//commands to perform
End
Functions and sub functions accessibility in a single .m file
Only the function placed at the top of the .m file can be accessed at the command line
Creating global variables
Global ‘variable name’
Pause MATLAB for a period of n seconds
Pause(n)
What does max(variable/array/matrix) return
Max(variable/array/matrix) can return the max number and the position of the max number
Generating random integer numbers
Generating random numbers with mean of 0 and standard deviation of 1
Integer= randi(integer range,size)
Normal distribution= randn(size)
How to Change a variable to fixed point
Fix(variable)
Generating zeros of a certain size
Generating ones of a certain size
Generating integers of a certain size
Zeros = zeros(size) Ones = ones(size) Integers = integer*ones(size)
What does the return command in a function do
Stops the function from further executing and returning to the command line
Purpose of nargin function for creating polymorphic functions
Returns number of actual input arguments given to the function
Eg if function is given 3 input arguments, nargin returns a value of 3
Function ‘function name’(x,y)
If ‘function name’(3,2) is called then nargin returns a value of 2 when used
Purpose of nargout function for creating polymorphic functions
returns the number of output arguments requested by the function caller
Eg. If function called as [x y] = ‘function name’
Then nargout returns a value of 2
What is the correct operator to use for 5 AND 6
What is the correct operator to use for 2 OR -2
What are these operators called
What is the correct operator to use for 5 AND [1 2 3]
What is the correct operator to use for 2 OR [-2 0 7]
What are these operators called
- &&
- ||
Scalar logical operators
- &
- |
Array logical operators