Making Bode Plots with GUI in MATLAB

In summary, the conversation discusses a programming issue where the user is trying to create a program to generate a bode plot using a transfer function. They are facing errors and difficulties with the code and are seeking advice on how to solve them. The conversation also mentions a question about plotting the transfer function in a separate window. The expert suggests converting strings to numbers and checking the input values, as well as using the figure() and bodeplot() functions to plot in a separate window. The expert concludes by offering further assistance if needed.
  • #1
DianeS
4
0
Hello guys! I have an issue, I'm trying to make a program in which you can get a bode plot by knowing the transfer function in guide. The basic idea is this: you enter 4 numbers in the interface and by those numbers you can know the transfer function, basically I'm doing this as a final step:

a = get(handles.T1_editText,'String');
b = get(handles.T2_editText,'String');
c = get(handles.T3_editText,'String');
d = get(handles.T4_editText,'String');
num=[a*b,a+b,1];
den=[c*d,c+d,1];
sys=tf(num,den);
bode(sys)
guidata(hObject, handles);

I know there is something wrong with it, because I'm not getting the same plots i get in MATLAB to check the results (i write the transfer function in numbers). And another problem i have is that When i enter certain values I don't even get a plot and i get this message:

? Error using ==> mtimes
Inner matrix dimensions must agree.

Error in ==> lol>Grafica_pushbutton_Callback at 213
num=[a*b,b+a,1];

Error in ==> gui_mainfcn at 96
feval(varargin{:});

Error in ==> lol at 42
gui_mainfcn(gui_State, varargin{:});

Error in ==> @(hObject,eventdata)lol('Grafica_pushbutton_Callback',hObject,eventdata,guidata(hObject))


? Error while evaluating uicontrol Callback

Which doesn't happen with different values.
Oh and one more thing, when i get do get the plot, it's all over my GUI screen, and i can't even see, is there a way to plot it in a different window by using a command?

I'll put up some images of what I'm talking about so you have a better idea.

2ikxzp.png


I'm kinda new to this MATLAB stuff, so try to bare with me :)
Thanks in advance for your answers.
 
Physics news on Phys.org
  • #2


Hello there! It seems like you are facing some issues with your code and getting the desired results. I can offer some suggestions that might help you solve your problems.

Firstly, it is important to understand the error message you are getting. The "Inner matrix dimensions must agree" error occurs when you are trying to multiply two matrices with incompatible dimensions. In your code, you are trying to multiply two strings (a and b) which is not a valid operation. To fix this, you can convert the strings to numbers using the str2double() function. For example, a = str2double(get(handles.T1_editText,'String')); This will convert the string to a number and then you can perform the multiplication operation.

Secondly, it is important to check the values you are entering in the interface. If you are getting an error with certain values, it could mean that those values are causing the error. Make sure to enter valid values for the transfer function.

Regarding your question about plotting in a separate window, you can use the figure() function to create a new figure window and then use the bodeplot() function to plot your transfer function in that window. For example, figure(); bodeplot(sys); This will create a new figure window and plot your transfer function in it.

I hope these suggestions will help you solve your problems. Good luck with your program! Let me know if you need any further assistance.
 

1. What is a Bode plot and why is it useful in MATLAB?

A Bode plot is a graphical representation of the frequency response of a system. It plots the magnitude and phase of a system's transfer function as a function of frequency. In MATLAB, it is useful for analyzing the stability and performance of control systems.

2. How do I create a Bode plot using MATLAB's GUI?

To create a Bode plot using MATLAB's GUI, you can use the "bode" command and specify the transfer function or system model as the input. Alternatively, you can use the "Frequency Response" tool in the Control System Designer app to interactively design and analyze Bode plots.

3. Can I customize the appearance of my Bode plot in MATLAB?

Yes, you can customize the appearance of your Bode plot in MATLAB by using various formatting options such as changing the axes labels, colors, line styles, and adding legends. You can also adjust the frequency and magnitude ranges to focus on specific areas of interest in the plot.

4. How can I use Bode plots to analyze the stability of a control system?

Bode plots can be used to analyze the stability of a control system by examining the phase margin and gain margin. The phase margin represents the amount of phase lag in the system before it becomes unstable, and the gain margin represents the amount of gain that can be added before the system becomes unstable. A stable system should have a phase margin greater than 0 degrees and a gain margin greater than 1.

5. Is it possible to export Bode plots from MATLAB for use in other programs or documents?

Yes, it is possible to export Bode plots from MATLAB for use in other programs or documents. You can save the plot as an image file (such as JPEG, PNG, or PDF) or copy and paste the plot into another program. You can also export the plot data as a matrix or table for further analysis in other software.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
12K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top