Define a function, MATLAB Programming

Define a function:

The radius of a circle is passed to the function to input argument  rad; the function computes the area of this circle and stores it in the output argument area. In the function header, we have reserved word function, then an output argument area followed by an assignment operator =, then the name of the function (similar as the name of the M-file), and then the input argument  rad, that is the radius. As there is an output argument in the function header, anywhere in the body of the function we should assign a value to this output argument. This is how the value is returned from a function. In this situation, the function is easy and all we have to do is assign to the output argument area the value of the built-in constant pi multiplied by the square of the input argument rad.

The function can be exhibited in the Command Window by using the  type command.

>> type calcarea

function area = calcarea(rad)

% This computes the area of a circle

area = pi * rad * rad;

 

 

Posted Date: 10/18/2012 7:17:04 AM | Location : United States







Related Discussions:- Define a function, Assignment Help, Ask Question on Define a function, Get Answer, Expert's Help, Define a function Discussions

Write discussion on Define a function
Your posts are moderated
Related Questions
giv a malab code for offline signature veification and recognition

Create MATLAB program(s) that solve a problem of your own choice. You may opt to solve work related problem, an industrial problem, or problem from your research project. Markin

1. Write a function to threshold your images separating the background from the foreground: Implement the "peakiness" detection algorithm described in class. The output of your

How do I compute and plot a temperature profile along the x axis from -6 to 6 given the equation for steady state heat conduction and boundary conditions

Function definitions: There are various ways to organize the scripts and functions, but for now every function which we write will be stored in a separate M-file, that is why


How do you write a programme that asks the user for a number between 1 and 1000 and calculates the sum of its digits?

This problem description is taken from Illingworth and Golosnoy [1]: For physical systems of inhomogeneous composition, di usion is often observed to cause a change of phase, even

how to design a digital fir filter using anfis in matlab.get the code for that.

You">http://www.cs.utsa.edu/~cs1173/labs/laboratory2.html You can go to this link and it should come up I need this by tommorow at 10:00 I just need the published part where you r