Passing structures to functions, MATLAB in Engineering

Assignment Help:

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.


Related Discussions:- Passing structures to functions

Symbolic variables and expressions, Symbolic Variables and expressions: ...

Symbolic Variables and expressions: The MATLAB has a type known as sym for the symbolic variables and expressions; these work with strings. The illustration, to generate a sym

Interchange rows - gauss-jordan elimination, Interchange rows : for illust...

Interchange rows : for illustration interchanging rows ri and rj is written as

Is functions in matlab, IS Functions in Matlab: There are many functio...

IS Functions in Matlab: There are many functions which are built into MATLAB which test whether or not something is true; these function names start with the word is. As these

Example of plotting from a function, Example of Plotting from a Function: ...

Example of Plotting from a Function: For illustration, the function can be called as shown below:      >> y = [1:2:9].^3      y =     1  27  125  343  729

Frd to ss, I have a frequency response data. How do I convert that to state...

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?

Algorithm for appex subfunction, Algorithm for appex subfunction: The ...

Algorithm for appex subfunction: The algorithm for appex subfunction is as shown:  Receives x & n as the input arguments.  Initializes a variable for running sum of t

Execution steps - modular program, Execution steps: Whenever the progr...

Execution steps: Whenever the program is executed, the steps below will take place: The script calcandprintarea starts executing. The calcandprintarea calls the readr

Example of gauss-jordan, Example of Gauss-jordan: For a 2×2 system, th...

Example of Gauss-jordan: For a 2×2 system, this would results and for a 3 × 3 system, Note that the resulting diagonal form does not involve the right-most col

Set operations, Set Operations: The MATLAB has numerous built-in funct...

Set Operations: The MATLAB has numerous built-in functions which perform set operations on vectors. These involve intersect, union, setdiff, unique, and setxor. All these func

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

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!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd