How to change line width in stepplot to then use with an updateSystem command?

25 views (last 30 days)
Hello
Using yoru code found in https://www.mathworks.com/help/control/ug/build-app-with-interactive-plot-updates.html it seems impossible to change the line appearance (coor, width, markers, etc.)
This seems to require a peculiar plot handle that prevents using a simple plot command.
How could this be done?
Regards
S.B.

Answers (1)

Payas Bahade
Payas Bahade on 27 Nov 2019
Hi Stephane,
The line appearance (color and marker) in ‘stepplot’ with interactive response-plot updates, can be changed by specifying them as input arguments. Below mentioned code illustrates how it can be done.
%Defining initial values of second-order dynamic system
zeta = .5; % Damping Ratio
wn = 2; % Natural Frequency
sys = tf(wn^2,[1,2*zeta*wn,wn^2]);
% Creating figure for GUI and configuring the axes for displaying step response
f = figure;
ax = axes('Parent',f,'position',[0.13 0.39 0.77 0.54]);
h = stepplot(ax,sys,'r--');% specifying marker style and color
setoptions(h,'XLim',[0,10],'YLim',[0,2]);
%adding slider and slider label text to the figure
b = uicontrol('Parent',f,'Style','slider','Position',[81,54,419,23],'value',zeta, 'min',0, 'max',1);
bgcolor = f.Color;
bl1 = uicontrol('Parent',f,'Style','text','Position',[50,54,23,23],'String','0','BackgroundColor',bgcolor);
bl2 = uicontrol('Parent',f,'Style','text','Position',[500,54,23,23],'String','1','BackgroundColor',bgcolor);
bl3 = uicontrol('Parent',f,'Style','text','Position',[240,25,100,23],'String','Damping Ratio','BackgroundColor',bgcolor);
% Setting callback that updates the step response plot as the damping ratio slider is moved.
b.Callback = @(es,ed) updateSystem(h,tf(wn^2,[1,2*(es.Value)*wn,wn^2]));
To change line width, Property inspector can be used. For this you need to navigate to required line object (Figure 1 > Axes > sys > Line) and specify the line width as required.
Output:
dfg.png
Hope this helps!
  2 Comments
Stephane Blouin
Stephane Blouin on 28 Nov 2019
Hello
This solution does NOT answer the question which was about "line width". So is it feasible or not? It seems that it cannot be done in a programmatic manner.
Regards
Stephane
Payas Bahade
Payas Bahade on 5 Dec 2019
Hi Stephane,
I have modified previous code to change line width programmatically. See if it solves your issue.
Code:
%Defining initial values of second-order dynamic system
zeta = .5; % Damping Ratio
wn = 2; % Natural Frequency
sys = tf(wn^2,[1,2*zeta*wn,wn^2]);
% Creating figure for GUI and configuring the axes for displaying step response
f = figure;
ax = axes('Parent',f,'position',[0.13 0.39 0.77 0.54]);
h = stepplot(ax,sys,'r--');% specifying marker style and color
setoptions(h,'XLim',[0,10],'YLim',[0,2]);
% To find all the graphic object handles of the figure
h1=findall(f);
% To find the line object handle from the list of graphic object handles
hline=findobj(h1,'Type','line','Tag','Curves');
% To set the line width
hline(1).LineWidth=4;
%adding slider and slider label text to the figure
b = uicontrol('Parent',f,'Style','slider','Position',[81,80,419,23],'value',zeta, 'min',0, 'max',1);
bgcolor = f.Color;
bl1 = uicontrol('Parent',f,'Style','text','Position',[50,80,23,23],'String','0','BackgroundColor',bgcolor);
bl2 = uicontrol('Parent',f,'Style','text','Position',[500,80,23,23],'String','1','BackgroundColor',bgcolor);
bl3 = uicontrol('Parent',f,'Style','text','Position',[240,51,100,23],'String','Damping Ratio','BackgroundColor',bgcolor);
% Setting callback that updates the step response plot as the damping ratio slider is moved.
b.Callback = @(es,ed) updateSystem(h,tf(wn^2,[1,2*(es.Value)*wn,wn^2]));
Output:
dfg12.png
HTH!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!