Question: ME021 - Engineering Computing - Fall 2017 Assignment HW 10 (Matlab) Due the week of November 6,2nd lab session Matlab Function Optional Parameter Values Matlab

 ME021 - Engineering Computing - Fall 2017 Assignment HW 10 (Matlab)

ME021 - Engineering Computing - Fall 2017 Assignment HW 10 (Matlab) Due the week of November 6,2nd lab session Matlab Function Optional Parameter Values Matlab functions can assume default values if the function is called with no value for a given parameter. We see something similar in the plot function. If we call plot (x,y,c) then Matlab plots y versus x with the values given in the c string for things like line color, marker shape, line type, etc. But, if we call plot (x,y), then Matlab plots y versus x and just uses the defaults for c. There is a parameter available inside functions called nargin. It stores the number of parameters ("arguments") that were passed to the function. We can use that to have the function do different things (such as assign default values) depending on the number of parameters that were passed to the function. Here is an example function. h PlotilthLabel * y1b1 and x1b1 not given end if {nargin ylbl, xibl, and c not given plot (x,Y) else plot(x.y.c) end xlabel(xibl) ylabel(ylbl); You can experiment with that function, both with and without the optional parameters to see how it works. ME021 - Engineering Computing - Fall 2017 Assignment HW 10 (Matlab) Due the week of November 6,2nd lab session Matlab Function Optional Parameter Values Matlab functions can assume default values if the function is called with no value for a given parameter. We see something similar in the plot function. If we call plot (x,y,c) then Matlab plots y versus x with the values given in the c string for things like line color, marker shape, line type, etc. But, if we call plot (x,y), then Matlab plots y versus x and just uses the defaults for c. There is a parameter available inside functions called nargin. It stores the number of parameters ("arguments") that were passed to the function. We can use that to have the function do different things (such as assign default values) depending on the number of parameters that were passed to the function. Here is an example function. h PlotilthLabel * y1b1 and x1b1 not given end if {nargin ylbl, xibl, and c not given plot (x,Y) else plot(x.y.c) end xlabel(xibl) ylabel(ylbl); You can experiment with that function, both with and without the optional parameters to see how it works

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!