MATLAB: Step Plots Urgent Assistance Needed

In summary, you can generate a step plot in MATLAB by defining the time vector and y vector, assigning the appropriate values to y, and then using the plot function to plot the step plot on the desired axes.
  • #1
Altairs
127
0
MATLAB : Step Plots [Urgent]

I am stuck at very crucial stage. I want to generate the step plot which is generated using step command in simple MATLAB environment. However, I am trying to incorporate it in GUI where it should plot the step plot when clicked on the button.

Following is the code for writing in normal MATLAB environment i.e. without GUI :-

Code:
m=1000;
b=50;
num=[1];
den=[m b];
cruise=tf(num,den);
Kp = 600;
Ki = 1;
contr=tf([Kp Ki],[1 0]);	
sys_cl=feedback(contr*cruise,1);
u=10;
t=0:0.1:20;
step(u*sys_cl,t)
axis([0 20 0 10])

Taken from http://www.engin.umich.edu/class/ctms/examples/cruise/ccpid.htm"

I am trying to put the same thing under the button callback and it just doesn't show on the axes I have made. The axes just disappear and nothing happens. However, the simple plot command works all right.

Following is my MATLAB code :-

Code:
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.axes1)
k=get(handles.edit1,'String');
Kp=str2num(k);
m=1000;
b=50;
u=10;
num=[1];
den=[m b];
cruise=tf(num,den);
sys_cl=feedback(Kp*cruise,1);
t=0:0.1:20;
step(u*sys_cl,t);
guidata(hObject, handles);

So how do I plot the unit step plot on those axis ? Is there someway to plot the step function using plot ?
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
Yes, you can plot the step plot using the plot function in MATLAB. To do this, you would need to specify the coordinates of each step. For example, for a unit step plot with time values from 0 to 10, you can use the following code: t = 0:0.1:10; % Define time vector y = zeros(length(t), 1); % Preallocate y vector y(t>=0) = 1; % Assign a value of 1 to all values of t greater than or equal to 0 plot(t, y); % Plot the step plot
 
  • #3


I understand the urgency of your situation and I am here to provide assistance. The first thing to check is if your GUI is properly configured to display the plot. Make sure that the axes are correctly defined and that the plot function is properly called within the callback function. You can also try using the 'hold on' command before calling the step function to ensure that the plot is not overwritten by any other commands. If these steps do not work, you can also try using the 'plot' function instead of 'step' and manually creating the step plot using the unit step function. I hope this helps and please let me know if you need further assistance.
 

1. What is a step plot in MATLAB?

A step plot in MATLAB is a type of graph that displays a step function, where the value remains constant until a certain point, then changes to a new value. It is commonly used to visualize data that changes abruptly at specific points or intervals.

2. How do I create a step plot in MATLAB?

To create a step plot in MATLAB, you can use the "stairs" function. This function takes two vectors as inputs, one for the x-axis values and one for the corresponding y-axis values. It then plots a step function connecting the points defined by the two vectors.

3. Can I customize the appearance of a step plot in MATLAB?

Yes, you can customize various aspects of a step plot in MATLAB such as the color, line style, and marker style. You can use the "plot" function with the "stairs" function to customize these properties. Additionally, you can add a title, labels, and a legend to your plot using the appropriate functions.

4. How do I add multiple step plots in one figure in MATLAB?

To add multiple step plots in one figure in MATLAB, you can use the "hold on" command after the first plot. This will allow you to plot additional step functions on the same figure without erasing the previous plot. You can also use the "subplot" function to create a grid of plots within one figure.

5. Are there any built-in functions for analyzing step plots in MATLAB?

Yes, MATLAB has several built-in functions for analyzing step plots, such as "stepinfo" and "stepplot". These functions can be used to calculate and visualize important parameters such as rise time, settling time, and overshoot in a step response. They can also be used to compare the response of different systems.

Similar threads

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