question on callback between pushbuttons ? Uigetfile to load automatically ?

3 次查看(过去 30 天)
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 个评论
Karthik KJ
Karthik KJ 2012-7-5
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 2012-7-5
I can load the matfile just by saying load *.mat file but I have to use the same GUI for manual and auto mode.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2012-7-5
编辑:Image Analyst 2012-7-5
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 个评论
Karthik KJ
Karthik KJ 2012-7-5
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 2012-7-5
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..

请先登录,再进行评论。

类别

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