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

조회 수: 63 (최근 30일)
Stephane Blouin
Stephane Blouin 2019년 11월 24일
댓글: Payas Bahade 2019년 12월 5일
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.

답변 (1개)

Payas Bahade
Payas Bahade 2019년 11월 27일
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
Stephane Blouin
Stephane Blouin 2019년 11월 28일
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 2019년 12월 5일
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!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Plot Customization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by