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

 Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Mayo de 2022

0 votos

Change
plot(app.UIAxes,gain,f);
to
bodeplot(app.UIAxes, gain, {0,f} );

6 comentarios

Ye Ken Kok
Ye Ken Kok el 22 de Mayo de 2022
It displays an error
That is a nuisance. You will need to do something like
[mag, phase, w] = bode(gain, {1, f});
That will return the magnitude and phase responses, and the frequencies corresponding. Normally magnitude and phase would be in separate plots, but you can proceed to plot(app.UIAxes, w, mag) and do whatever is suitable for the phase.
Ye Ken Kok
Ye Ken Kok el 22 de Mayo de 2022
Well I tried what you said, but it showed another error stating that the data should not have 2 dimensions
%setup for demo purposes
app.UIFigure = figure(); %uifigure();
app.UIFigure.Position = [100 100 1222 499];
app.UIAxes = uiaxes(app.UIFigure);
f = 50;
%end setup for demo
R = 1000;
C = 1/(2*pi*R*f);
gain = tf(1, 1+(2*pi*R*C))
gain = 0.9804 Static gain.
[mag, phase, w] = bode(gain, {1, f});
plot(app.UIAxes, w, squeeze(mag), 'DisplayName', 'magnitude')
hold(app.UIAxes, 'on');
plot(app.UIAxes, w, squeeze(phase), 'DisplayName', 'phase');
legend show
Ye Ken Kok
Ye Ken Kok el 22 de Mayo de 2022
After I run the program the graph is plotted on the GUI but the legend appears in another tab
legend(app.UIAxes, 'show')
Note: you are never going to have negative frequencies for this purpose.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 22 de Mayo de 2022

Comentada:

el 22 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by