question on callback between pushbuttons ? Uigetfile to load automatically ?

3 visualizzazioni (ultimi 30 giorni)
Hi,
I have created an GUI with name autoruncheck and i have 2 pushbuttons. With pushbutton1, I call pushbutton2 and I have chosen to load an mat file in pushbutton2. What i need is, pushbutton2 should automatically load the mat file without user loading it. How it can be done. I would also want to know the way I callback Pushbutton2 is correct ? is there any other way for callback ?
function pushbutton1_Callback(hObject, eventdata, handles)
autoruncheck('pushbutton2_Callback',handles.pushbutton2,[],handles)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
[FileName,PathName] = uigetfile('Step02.mat','Select mat file');
NAME = [PathName,FileName];
evalin('base',['load ' NAME]);
  3 Commenti
Karthik KJ
Karthik KJ il 5 Lug 2012
basically this is a short form of my GUI, and used just to explain it. In my GUI there are two ways for the user, 1 is manual, other is auto. In manual setting, the user can click pushbutton2 and load the mat file and in Auto setting user will click only pushbutton1,it will then call pushbutton2 and then another pushbutton and so on.....
Karthik KJ
Karthik KJ il 5 Lug 2012
I can load the matfile just by saying load *.mat file but I have to use the same GUI for manual and auto mode.

Accedi per commentare.

Risposte (1)

Image Analyst
Image Analyst il 5 Lug 2012
Modificato: Image Analyst il 5 Lug 2012
I'd have pushbutton1 say "Specify File then Process..." and call uigetdir and then a function called ProcessFile(fullFileName). Pushbutton2's caption would say "Process default file" and would just assign some default fullFileName and then call the same function ProcessFile(fullFileName).
ProcessFile(fullFileName) would be a function that you write that takes whatever filename is passed, however it might be created, in and do something with it. So the pushbutton 1 and 2 are merely different ways of getting that filename, one via the user browsing, and the second "automatically" by assigning some default filename.
  2 Commenti
Karthik KJ
Karthik KJ il 5 Lug 2012
Thanks, i can work out. One more question, with the same situation is it possible to callback pushbutton1 automatically when GUI opens.
Image Analyst
Image Analyst il 5 Lug 2012
Yes. Same basic process. Just create a new function that does what's inside the pushbutton 1 callback - let's say it's SpecifyFileAndProcess(). Then you just call that function both within the OpeningFcn() start up code, and within the pushbutton 1 callback. You will need to pass in handles in the argument list if you need to use it inside SpecifyFileAndProcess(), say if you need to get the values of any sliders, edit fields, radio buttons, checkboxes, etc..

Accedi per commentare.

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by