How do I plot sin(x), cos(x) and tan(x) when they are selected on the drop down for MATLAB app designer?

12 views (last 30 days)
I am creating an app that will give you the derivative of the selected trig identity and then it will graph, of the three options, cos(x), sin(x), or tan(x), whichever one is chosen for the derivative. I currently have the app working to where when you click the equals button it give you the derivative of that chosen trig identity in the label but I want to connect the UI Axes to the button where when I hit equal on either cos(x), sin(x), or tan(x) it will show the graph of each trig identity. I am unsure on how to make this function work. I will attach my code view and design view below.

Accepted Answer

Walter Roberson
Walter Roberson on 2 May 2023
switch method
case 'Sinx'
result = 'Cosx';
fun = @cos;
case 'Cosx';
result = '-Sinx';
fun = @(x)-sin(x);
case 'Tanx';
result = 'Sec^2x';
fun = @(x) sec(x).^2;
and so on.
Then at some point in the function you need to create an x vector and apply fun() to the vector to get the values to plot.
I suggest you also consider the possibilities of using ItemsData https://www.mathworks.com/help/matlab/ref/uilistbox.html#buijl86-1_sep_shared-ItemsData -- it can save you having to use a switch or if/elseif

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!