Already have an account? Get multiple benefits of using own account!
Login in your account..!
Remember me
Don't have an account? Create your account in less than a minutes,
Forgot password? how can I recover my password now!
Enter right registered email to receive password!
Example of Functions which return values:
Calling this function prints the circumference, since there is no way to store the value, hence, it can be used in following computations:
>> calccircum1(3.3)
20.7345
As no value is returned by the function, it would be an error to attempt to store the value in a variable:
>> c = calccircum1(3.3)
??? Error using ==> calccircum1
Too many output arguments.
By dissimilarity, the function below computes and returns the circumference, and hence, it can stored and used in other computations. For illustration, if the circle is the base of a cylinder, and we wish to compute the surface area of the cylinder, we would require to multiply the result from the calccircum2 function by the height of the cylinder.
>> circumference = calccircum2(3.3)
circumference =
>> height = 4;
>> surf_area = circumference * height
surf_area =
82.9380
Example of Nested functions: For illustration, the function below computes and returns the volume of a cube. Three arguments are then passed to it, for the width and length of
Help function: Function is computing the two values, there are two output arguments in the function header (i.e., area & circum), that are placed in the square brackets [ ]. A
Index vector: The index vector is then used as the indices for original vector. To get grades vector in ascending order, the indices used would be grades (2), grades (5), and
function sortrows - sorting strings: The function sortrows sorts each and every row as a block, or group, and it also will work on numbers. Here in this illustration the rows
Example of Vectorizing: Likewise, for an operation on a matrix, a nested loop would be needed; for illustration, supposing a matrix variable mat: [r c] = size(mat); for
Function Stubs: The other common debugging method, which is used when there is a script main program which calls many functions, is to use the function stubs. A function stub
Execution of persistent variables: The functions can also be called from the script or from the Command Window, as shown here. For illustration, the functions are called first
Reading from Files: There are many lower level functions which read from files. The function fscanf reads the formatted data into a matrix, by using conversion formats like %s
Example of Median For the vector [1 4 5 9 12 33], the median is the average of the 5 & 9 in the middle: >> median([1 4 5 9 12 33]) ans = 7
Editor/Debugger: The MATLAB has numerous useful functions for debugging, and debugging can also be completed through its editor, which is known as the Editor/Debugger. Typi
Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!
whatsapp: +91-977-207-8620
Phone: +91-977-207-8620
Email: [email protected]
All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd