Question: 7. Question Function (use matlab) (1). Create a function plotSinFunc to recognize the number of input arguments automatically. (2). If the number of input argument

7. Question Function (use matlab)

(1). Create a function plotSinFunc to recognize the number of input arguments automatically.

(2). If the number of input argument is 1 (we can call it like plotSinFunc(f1)), create a time series

x=linspace(0, pi, f1*20+1), and plot the sin(2x). You should use squares as markers and a dashed

red line of thickness 2 for the line. Set the marker face color to be black (properties are

LineWidth, MarkerFaceColor)

(3). If there are 2 inputs, i.e. function usage like plotSinFunc(f1, f2), create two time series

x1=linspace(0, pi, f1*20+1) and x2=linspace(0, pi, f2*15+1), and, open a new figure with 2 axes,

plot sin(2*x1) on top and plot sin(x2) on the bottom.

(4). If the number of input arguments is other, display 'Only one or two inputs are allowed'.

(5). Think about the possibility of a negative number as the input. How to recognize it in your

function, and try to write a robust function.

(6). In a script .m file to call the plotSinFunc with the input arguments:

a) Only one arguments: 12

b) Two arguments: (12, 60)

c) Two arguments: (12, -12)

Hint: the number of input arguments are in the built-in variable nargin.

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!