Plot graph in App Designer

4 views (last 30 days)
Ye Ken Kok
Ye Ken Kok on 22 May 2022
Commented: Walter Roberson on 22 May 2022
I need to plot a graph with the 2 axes being gain and frequency. The code is as below but I can't plot it since my gain is not numeric. How else should I plot it?
% Button pushed function: LOWPASSFILTERButton
function LOWPASSFILTERButtonPushed(app, event)
% INPUT USED
% R = Resistance (Ohms)
% f = Frequency (Hz)
% C = Capacitance (C)
% OUTPUT
% H(s) = Gain
% To check selection for resistance
selection = app.ResistanceOhmsDropDown.Value;
% To assign a value to the selections
if selection == '1k'
value = 1;
elseif selection == '2k'
value = 2;
elseif selection == '3k'
value = 3;
elseif selection == '4k'
value = 4;
end
% Conditions for each selections
switch value
case 1
% specify inputs
R = 1000;
f = app.CutoffFrequencyHzEditField.Value;
C = 1/(2*pi*R*f);
% Calculate gain
gain = tf(1,1+(2*pi*R*C));
% plot graph
plot(app.UIAxes,gain,f);
end

Accepted Answer

Walter Roberson
Walter Roberson on 22 May 2022
Change
plot(app.UIAxes,gain,f);
to
bodeplot(app.UIAxes, gain, {0,f} );
  6 Comments
Ye Ken Kok
Ye Ken Kok on 22 May 2022
After I run the program the graph is plotted on the GUI but the legend appears in another tab
Walter Roberson
Walter Roberson on 22 May 2022
legend(app.UIAxes, 'show')
Note: you are never going to have negative frequencies for this purpose.

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D 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!