필터 지우기
필터 지우기

GUI Pushbutton, accessing another file

조회 수: 6 (최근 30일)
Craig
Craig 2011년 2월 23일
Hello,
I am fairly new to matlab, and attempting to make a basic GUI that has two pushbuttons, along with some other things. My question relates to the pushbuttons. I am wondering how to write the code so that when the user clicks a pushbutton, it opens up another file.
So, matlab automatically brings up:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
and I am wondering where I put in code to allow the pushbutton, when clicked, to open up my other m file?
Cheers~

채택된 답변

Matt Fig
Matt Fig 2011년 2월 23일
Do you mean that your file is hardcoded into the GUI? If so, put this in the pushbutton callback:
edit mfilename
where you replace mfilename with the name of your M-File.
If the file is not in the current directory, you will have to add the path.
If that is not what you meant, you might want to use UIGETFILE instead:
[fnam,pth] = uigetfile('*m')
edit([pth fnam])
  댓글 수: 6
Craig
Craig 2011년 2월 25일
Ah, sorry for the confusion, my mistake; running the file is what I wanted.
Yes, I just looked, and there is a command for close all. Got rid of that, and it works quite well. Thank you so much for the help, much appreciated.
I do have another question, if you wouldn't mind. I have a folder of files I wish to display in a listbox, then have the user select a file from the box, then click another pushbutton to run the selected file. I was looking at http://www.mathworks.com/help/techdoc/creating_guis/f6-7446.html#f6-11263 but was confused where the path to the directory goes or how I add that.
Thanks again.
Matt Fig
Matt Fig 2011년 2월 25일
I recommend you select a best answer for this thread, then start a new one because this is a new topic.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Paulo Silva
Paulo Silva 2011년 2월 25일
fig=figure
uicontrol('Style','pushbutton','String','Start',...
'Callback','SomeMFileNameIWantToOpen',...
'Units','Normalized','Position',[0.5 0.5 0.1 0.1],...
'Parent',fig)
  댓글 수: 2
Matt Fig
Matt Fig 2011년 2월 25일
He is using GUIDE...
And this is not advisable if there could be more than that simple call to run the other M-File in the callback.
noxnoxmox
noxnoxmox 2013년 4월 3일
It is so helpful. You saved my day ^_^

댓글을 달려면 로그인하십시오.

카테고리

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