App Designer - Trying to modify a plotted axes line on a (figure with UIControls) called from the app.

3 次查看(过去 30 天)
I'm trying to build an interactive figure that when the check box is checked or uncheck it displays the intended line or deletes the line. Delete can mean hide too. I can get the figure to display just fine but when I check/uncheck the checkbox I get
"Not enough input arguments"
for
line(axi,'XData',Time,'YData',Data1,'LineStyle','none');
Here's the whole thing
function buildUIFigure(~) % Need the ~ instead of app.
f = figure('Name','Data Selection','Position',[0 0 1100 900]);
% CheckBox1 Label
uicontrol(...
'Parent',f...
'Style','text',...
'Position',[55 650 120 20]...
'HorizontalAlignment','left',...
'String','First Check Box',...
'FontSize',14,...
'FontWeight','bold');
% CheckBox1 UIControl
CheckBox1 = uicontrol(...
'Parent',f,...
'Style','checkbox',...
'Position',[180 652 15 15],...
'CallBack',@VisualizeData,...
'Value',1);
ax = axes(...
'Parent',f,...
'Position',[0.25 0.1 0.7 0.85],...
'box','on');
line(Time,Data1,'Color','k');
drawnow
uiwait(f) % Wait for the user to close figure before moving on.
function VisualizeData (CheckBox1,Time,Data1)
axi = gca;
DispCheckBox1 = get(CheckBox1,'Value');
if DispCheckBox1 == 1
line(axi,'XData',Time,'YData',Data1,'Color','k');
elseif DispCheckBox1 == 0
% Trying to make it "disappear". Can't figure out how to delete the line altogether.
line(axi,'XData',Time,'YData',Data1,'LineStyle','none');
end
drawnow
end
end
I'm still reletively new to MATLAB and I might have picked a fairly ambitious app to make for my first! Lol. *cries

采纳的回答

Kris Hoffman
Kris Hoffman 2018-7-24
Well, in typical fashion, I semi-answered my own question...
function VisualizeData (CheckBox1,ax)
DispCheckBox1 = get(CheckBox1,'Value');
if DispCheckBox1 == 1
test = get(gca,'Children');
set(test(1),'Visible','on');
else
test = get(gca,'Children');
set(test(1),'Visible','off');
end
drawnow
end
This should work as long as the indexing cooperates.

更多回答(1 个)

fouad jabbour
fouad jabbour 2020-6-1
I have a transfert function and I want to view if the system is stable by cheking its roots if their lenght is less than 1 but is does not go well and I don't understand where is the errorError in Untitled2ex42zabatawwalnoss (line 20)
x =
uicontrol('Parent',f1,'Style','text','Position',[81,1000,419,10],'value','systheme
instable'); %the vector after position specified the dimensions and location of the
slider
the hole code is
clear
close all
f1=figure; %f identifies the figure and will be used later
hold on
axis equal
axis([-10 10 -10 10])
%limits of x and y visible on the figure. Observe the figure and
g = uicontrol('Parent',f1,'Style','slider','Position',[81,50,1000,10],'value',0, 'min',-90,'max',90); %the vector after position specified the dimensions and location of the slider
m = uicontrol('Parent',f1,'Style','slider','Position',[81,23,1000,10],'value',0, 'min',-90,'max',90); %the vector after position specified the dimensions and location of the slider
l = uicontrol('Parent',f1,'Style','slider','Position',[81,10,1000,10],'value',0, 'min',-90,'max',90); %the vector after position specified the dimensions and location of the slider
q = uicontrol('Parent',f1,'Style','slider','Position',[81,0,1000,10],'value',0, 'min',-90,'max',90); %the vector after position specified the dimensions and location of the slider
x = uicontrol('Parent',f1,'Style','text','Position',[81,1000,419,10],'value','systheme instable'); %the vector after position specified the dimensions and location of the slider
while(1) %infinite loop
k=get(g,'value'); %reading the current value of the slider
uicontrol('Parent',f1,'Style','text','Position',[50,50,23,10],'String',num2str(k));
%displaying the value in the figure
a=get(m,'value'); %reading the current value of the slider
uicontrol('Parent',f1,'Style','text','Position',[50,23,23,10],'String',num2str(a));
b=get(l,'value'); %reading the current value of the slider
uicontrol('Parent',f1,'Style','text','Position',[50,10,23,10],'String',num2str(b));
c=get(q,'value'); %reading the current value of the slider
uicontrol('Parent',f1,'Style','text','Position',[50,0,23,10],'String',num2str(c));
p=get(g,'value'); %reading the current value of the slider
%displaying the value in the figure
s=zeros(1,12);
for j=3:10
s(j)=k*a^(-1)-b*a^(-1)*s(j-1)-c*a^(-1)*s(j-2);
end
h=plot([j,s]);
y=[a , b, c];
z=roots(y);
%ici on calcule la racine carree de la fonction de transfert
n= y/y(1) ;
%on rend le coefficient de x du plusgrand exposant egal a 1
c1= abs(n) ;
%o calcul le module de chaque racine
o= any(c1(:) >1);
%ici on compare le module de tout les t=racines ,si une %d’eux est superieure a 1 le systheme est %instable
if o>=1
uicontrol('Parent',f1,'Style','text','Position',[50,500,23,10]);
%displaying the value in the figure
end
pause(0.1) %waiting 0.1 seconds
delete(h);
delete(p);
end

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by