Hello Hussein,
I understand that you want to build an app with MATLAB where you can plot tangents at specific point of the curve and also want to move and modify the tangent.
You can build such app with just 3 components in app designer. These are axes, button and slider.
First of all drag and drop all the mentioned components. Now you've to write the callback function for the button. This function will plot the curve and the tangent.
function PlotButtonPushed(app, event)
ytan = y1 + cos(x1).*(x-x1);
plot(app.UIAxes,x1, y1, 'r*', 'LineWidth', 2, 'MarkerSize', 4);
Here I've taken a sine curve and plotted a tangent at (pi,sin(pi)) initially. Once the curve and tangent are plotted, we can focus on moving the tangent. For that, callback of slider must be written.
function SliderValueChanging(app, event)
changingValue = event.Value;
tangent = app.UIAxes.Children(2,1);
pointer = app.UIAxes.Children(1,1);
pointer.XData = changingValue;
pointer.YData = sin(changingValue);
tangent.YData = sin(changingValue) + cos(changingValue).*(tangent.XData-changingValue);
All we need to do, is to just fetch the current value of the slider and plug that value in tangent equation accordingly. That's how tangent can be moved dynamically.
After creating the app follow the below steps
- Click the button to create the plot.
- Move the slider to move the tangent.
I hope this helps.