Calling a function into a pushbutton in GUI
Mostrar comentarios más antiguos
I have a button in my GUI which should run a function when pressed.I have made the function externally and I want it call it in the pushbutton. How can I go by doing that. could anyone please help me
Respuestas (2)
Azzi Abdelmalek
el 9 de Mzo. de 2013
0 votos
Just call your function in the callback of your push button
17 comentarios
Achchuthan Ganeshanathan
el 9 de Mzo. de 2013
Azzi Abdelmalek
el 9 de Mzo. de 2013
Yes, write whatever you want
Achchuthan Ganeshanathan
el 9 de Mzo. de 2013
Azzi Abdelmalek
el 9 de Mzo. de 2013
Your function should be in the same folder as your gui
Achchuthan Ganeshanathan
el 9 de Mzo. de 2013
Azzi Abdelmalek
el 9 de Mzo. de 2013
What is this ?
[Newfunction.m,Users/Achchu/Documents/MATLAB/Newfunction] = uigetfile({'*.*'},'Open Directory');
What do you want to do?
Achchuthan Ganeshanathan
el 9 de Mzo. de 2013
Azzi Abdelmalek
el 9 de Mzo. de 2013
This line is not correct, and I think, instead of trying some code from the web, you should learn how to use functions. You also need to learn basics of Matlab
Achchuthan Ganeshanathan
el 9 de Mzo. de 2013
Azzi Abdelmalek
el 9 de Mzo. de 2013
Ok, If you want to call a function, for example, If your function is
function y=filname(a,b)
%your code
To call it from you pushbutton calbback, just write, for example
a=10;
b=4
y=filname(a,b)
Achchuthan Ganeshanathan
el 9 de Mzo. de 2013
Azzi Abdelmalek
el 9 de Mzo. de 2013
Newfunction is a function or a script?
Achchuthan Ganeshanathan
el 9 de Mzo. de 2013
Azzi Abdelmalek
el 9 de Mzo. de 2013
If it's a function, then what are its inputs and outputs argument? can you post this function?
Achchuthan Ganeshanathan
el 9 de Mzo. de 2013
Editada: Azzi Abdelmalek
el 9 de Mzo. de 2013
Azzi Abdelmalek
el 9 de Mzo. de 2013
Editada: Azzi Abdelmalek
el 9 de Mzo. de 2013
Ok, then in a callback just write
% assign a value to h
h=100 % for example
Newfunction (h)
Azzi Abdelmalek
el 9 de Mzo. de 2013
Look, you have nothing to write in your editbox callback, the action is taken when the user click on pushbutton, then in your pushbutton callback write
h=str2double(get(handles.Speed_Callback,'string'));
Achchuthan Ganeshanathan
el 9 de Mzo. de 2013
6 comentarios
Azzi Abdelmalek
el 9 de Mzo. de 2013
What Callback is doing in your code? remove the line
Callback % assign a value to h
from your code
Achchuthan Ganeshanathan
el 9 de Mzo. de 2013
Azzi Abdelmalek
el 9 de Mzo. de 2013
Achchuthan, I suggest that you read the help of guide Matlab.
Achchuthan Ganeshanathan
el 9 de Mzo. de 2013
Azzi Abdelmalek
el 9 de Mzo. de 2013
Use an edit box, where the user can put the value of h, then in your pushbutton callback write
h=str2double(get(handles.edit1,'string'))
Achchuthan Ganeshanathan
el 9 de Mzo. de 2013
Categorías
Más información sobre Interactive Control and Callbacks en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!