Question
The MATLAB code shown below generates a plot of the line =3 2 +2x+5 in a new figure window. Copy the code below to a
The MATLAB code shown below generates a plot of the line =32+2x+5 in a new figure window. Copy the code below to a script m-file and add code to it to wait for the user to mouse-click somewhere within the figure axes. After clicking, display a new title on the plot which indicates whether they clicked above the line, or below the line. You will need to use the waitforbuttonpress and get(gca,'CurrentPoint') expressions.
The mouse clicks values are stored as a 2x3 array. Evaluate the equation of your line at your mouse-click x-value (try polyval); if this y-value is less than your mouse-y, then the click was above the line.
*What I have
coeff = [3 2 5]; % Define our lines coefficients
x = -10:10; % Define the 21-point x-range to evaluate (and plot)
polval(x)
zeros(2 3)
y = polyval (coeff,x); % Compute the 21 y-values of the line
figure(2); clf; % Open figure 2 and clear the figure (clf)
plot(x,y); grid on; % Plot the line and add a grid
title('Click anywhere on the Axes'); % Display initial instructions to the use
hold on
figure(2);
if % user makes selection above or below function
w = waitforbuttonpress;
axes;
mouse_y= (>=y)
%
get(gca,'CurrentPoint')
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