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]);
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!