"Error While Evaluating UIControl Callback"

3 views (last 30 days)
Tyler Robinson
Tyler Robinson on 2 Apr 2021
Answered: Asvin Kumar on 20 May 2021
I'm attempting to write a script that allows me to change the Damping Ratio value via a slider. The code below line 10 is not my code, and is copied from someone doing something similar but with a transfer function. It seems that the issue is in line 25 with the system update.
close all
clear all
zeta = .5; % Damping Ratio
wn = 2; % Natural Frequency
v = 0:.001:.05
Yo = 5E-2; M = 2000; k = 200;
w = sqrt(k/M);
lambda = .5; wf = (2*pi*v)/(lambda); xi = .5;
r = wf/w
x = Yo*(sqrt(1+(2*r.*xi).^2)./sqrt((1-r.^2).^2+(2*r.*xi).^2))
f = figure;
ax = axes('Parent',f,'position',[0.13 0.39 0.77 0.54]);
h = plot(v,x)
b = uicontrol('Parent',f,'Style','slider','Position',[81,54,419,23],...
'value',xi, 'min',0, 'max',1);
bgcolor = f.Color;
bl1 = uicontrol('Parent',f,'Style','text','Position',[50,54,23,23],...
bl2 = uicontrol('Parent',f,'Style','text','Position',[500,54,23,23],...
bl3 = uicontrol('Parent',f,'Style','text','Position',[240,25,100,23],...
'String','Damping Ratio','BackgroundColor',bgcolor);
b.Callback = @(es,ed) updateSystem(h, Yo*(sqrt(1+(2*r.*(es.Value).^2)./sqrt((1-r.^2).^2+(2*r.*(es.Value)).^2))));
  1 Comment
Tyler Robinson
Tyler Robinson on 2 Apr 2021
After a small search, I see that updateSystem works specifically for dynamic system response plots -- not what I've evaluated into the second argument. Is there a command that accomplishes what I'm trying to accomplish but for non-transfer functions?

Sign in to comment.

Answers (1)

Asvin Kumar
Asvin Kumar on 20 May 2021
If I understand correctly, you just want to update the plot. You can do that by calling the plot function in your callback with the appropriate handle so that the previous plot gets overwritten. Something like...
b.Callback = @() plot(h.Parent, ...) % fill in your expression in the 2nd and 3rd args
If you don't want the previous plot to get overwritten, you could use:
hold on

Community Treasure Hunt

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

Start Hunting!

Translated by