필터 지우기
필터 지우기

question on callback between pushbuttons ? Uigetfile to load automatically ?

조회 수: 3 (최근 30일)
Karthik KJ
Karthik KJ 2012년 7월 5일
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