Passing structures to functions, MATLAB in Engineering

Passing Structures to Functions:

The whole structure can be passed to a function, or separate fields can be passed. For illustration, here are the two distinct versions of a function which computes the profit on a software package. The profit is then defined as the price minus the cost.

In the first version, the whole structure variable is passed to the function, therefore the function should use the dot operator to refer to the price and cost fields of the input argument.

653_Passing Structures to Functions.png

>> calcprof(package)

ans =

19.9600

In the second version, merely the price and cost fields are passed to the function by using the dot operator in the function call. These are passed to the two scalar input arguments in function header; therefore there is no reference to a structure variable in the function itself, and the dot operator is not required in the function.

2117_Passing Structures to Functions1.png

>> calcprof2(package.price, package.cost)

ans =

19.9600

 

It is significant, as always with the functions, to make sure that the arguments in the function call correspond one-to-one with the input arguments in the function header. In case of calcprof, the structure variable is passed to an input argument that is a structure. For second function calcprof2, the two individual fields, that is double values, and is passed to two double arguments.

Posted Date: 10/20/2012 5:59:51 AM | Location : United States







Related Discussions:- Passing structures to functions, Assignment Help, Ask Question on Passing structures to functions, Get Answer, Expert's Help, Passing structures to functions Discussions

Write discussion on Passing structures to functions
Your posts are moderated
Related Questions
How can I use the weighted moving average formula in matlab to smooth a column data of 404 values?

Scaling:   change a row by multiplying it by a non-zero scalar sri →  ri For illustration, for the matrix:

Example of Interpolation and extrapolation: The MATLAB has a function to do this, known as polyfit. The function polyfit finds the coefficients of the polynomial of the partic

Illustration of Image processing: This displays that there are 64 rows, or in another word, 64 colors, in this specific colormap. It also displays that the first five colors a


Illustration of Matrix solutions: For illustration, consider the three equations below with 3unknowns x 1 ,x 2 , and x 3 : We can write this in the form Ax = b here A

Program of passing arguments to functions: This was an illustration of a function which did not receive any input arguments nor did it return any output arguments; it easily a

I have a frequency response data. How do I convert that to state space? I am given a 6 row and 3 column data (steady state). How do i convert that to state space model?

Illustration of if - else statement: The one application of an if-else statement is to check for errors in the inputs to a script. For illustration, a former script prompted t

For Loops which do not use an iterator Variable in the action: In all the illustrations that we seen so far, the value of the loop variable has been used in same way in the ac