How to make a callback from a pushbutton to a figure in MATLAB?

4 Ansichten (letzte 30 Tage)
Demeter Andreea
Demeter Andreea am 14 Aug. 2019
Kommentiert: Geoff Hayes am 14 Aug. 2019
Hei,
I wanted to ask you guys how I do the callback from this pushbutton from the main interface:
%PushButton Vc
uicontrol('Style','PushButton',...
'Units','normalized',...
'BackgroundColor',[0.0,0.0,0.0],...
'FontSize',8,...
'FontWeight','b',...
'ForegroundColor','W',...
'FontName','Consolas',...
'String','Matrice codare [Vc]',...
'Position',[0.08,0.15,0.12,0.08]);
To when I push the button to show me this new figure ( The code for figure is in another file saved):
%Figura Codare TORNADO
%--------------------------------------------------------------------------
figure()
set(gcf,'color','Black'); %setare background
%'Elementele matricii de codare liniara Tornado [Vc]'
uicontrol('Style','Text',...
'Units','Normalized',...
'Position',[0.1,0.6,0.5,0.4],...
'BackgroundColor',[0,0,0],...
'FontSize',12,...
'ForegroundColor','White',...
'FontWeight','b',...
'FontName','Consolas',...
'String','Elementele matricii de codare liniara Tornado [Vc]');
%Tabloul de valori
uicontrol('Style','Edit','Units','Normalize','position',[.1,.5,.6,.4],...
'Max',2,'String',num2str(Vc),'FontName', 'Consolas');
Thanks, please help
  3 Kommentare
Demeter Andreea
Demeter Andreea am 14 Aug. 2019
The problem is that it's that where I have that figure that I want to open pressing the pushbutton is just a file, not a function and if I try to make a function it gives me some errors, so I tried to open like this the file but still I have another erros now...
The code modified:
'Callback', run('FiguraVc.m'));
The errors:
Error using run
Too many output arguments.
Error in interf (line 217)
'Callback',run('FiguraVc.m'));
Error in mjfgkjsf (line 12) %the main program
interf(N,R,tip,s1,s2); % apel interfata
Geoff Hayes
Geoff Hayes am 14 Aug. 2019
Demeter - is FiguraVc.m a script or a function? If a script, try converting it into a function that you can call from your callback function. So like Adam indicated,
'Callback', @myFunction
where
function myFunction(~,~)
FiguraVc;
end
where I'm assuming that FiguraVc is the name of the function defined in the FiguraVc.m file.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by