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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started