MATLAB Function Handle Plotting

Generic Plotting Function

Problem Statement

Write a function that will receive data in the form of x and y vectors, and a handle to a plot function and will produce the plot.

For example, a call to the function would look like: wsfn(x, y, @bar)

function prob6(x, y, fh) %{ Problem Write a function that will receive data in the form of x and y vectors, and a handle to a plot function and will produce the plot. For example, a call to the function would look like wsfn(x,y,@bar). %} %{ Usage example: x = [1:.1:4]; y = sin(x); prob6(x,y,@bar); %} fh(x,y)

Function Usage Examples

% Example 1: Bar plot of sine function x = [1:.1:4]; y = sin(x); prob6(x, y, @bar); % Example 2: Line plot of cosine function x = 0:0.1:2*pi; y = cos(x); prob6(x, y, @plot); % Example 3: Stem plot of exponential function x = 1:10; y = exp(x/3); prob6(x, y, @stem); % Example 4: Stairs plot of logarithmic function x = 1:0.5:5; y = log(x); prob6(x, y, @stairs);


For more details, please contact me here.