필터 지우기
필터 지우기

Browse button in GUI in Matlab

조회 수: 27 (최근 30일)
saharsahar
saharsahar 2012년 2월 6일
댓글: Image Analyst 2022년 1월 13일
Dear All,
I am newby in Matlab GUI and I am designing a GUI with matlab which gets some directory from "browse pushbutton" , shows the directory in the "answer Edit text box" and after clicking "Load pushbutton", it should sende the value in the text box to main .m file. Also it should wait until the user browse at least something. what I did is in push buttond call back :
[FileName,FilePath]=uigetfile();
ExPath = [FilePath FileName];
set(handles.answer_edit,'String',ExPath);
guidata(hObject, handles);
So I am able to see the directory in "answer edit textbox". But My problem is in Load pushbutton. How I have to pass the results to another .mfile.
Also how I can control that the program should wait until user browse at least something in Edit textbox.
Any help is highly apprecietd.
  댓글 수: 2
Darshil Pragneshbhai Trivedi
Darshil Pragneshbhai Trivedi 2022년 1월 13일
Hello,
i am a new in this field, and still trying to learn as much as i can, i am working on the type of same thing but in Matlab App Designer, and i have to browse excel file with '.csv' extension, and the file i chose should be written in the editbox, and when i push the load, my GUI should take the data. after then i have to set it as a property so ican connect it with the other callbacks, but how i don't know, if You can help me out with it, it would be a great help from your side.
Image Analyst
Image Analyst 2022년 1월 13일
@Darshil Pragneshbhai Trivedi, attach your .mlapp file in a new question (not here).

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

채택된 답변

Image Analyst
Image Analyst 2012년 2월 7일
You need to delete the handle of the GUI to cause the output function to run and send control back to the calling program. Perhaps this codce will help. I have a button, called btnOK, and a GUI called figMoveMask. When I click OK this code executes and then calls the outputfcn and then returns to the main calling routine with output arguments in varargout, like you did.
%--------------------------------------------------------------------
% --- Executes on button press in btnOK.
% MoveMask exits and control returns to the calling program.
function btnOK_Callback(hObject, eventdata, handles)
% hObject handle to btnOK (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global maskVerticesXCoords;
global maskVerticesYCoords;
% Put the temp variables into our master global variable.
[newX, newY] = CalculateNewCoordinates(handles);
maskVerticesXCoords = newX;
maskVerticesYCoords = newY;
uiresume(handles.figMoveMask);
delete(handles.figMoveMask);
return; % to calling program.

추가 답변 (5개)

Image Analyst
Image Analyst 2012년 2월 6일
You could try a nice framework for doing all that. MAGIC http://www.mathworks.com/matlabcentral/fileexchange/24224
This GUI will help the novice user get up to speed very quickly on using GUI-based applications. Everything is laid out in a very simple Step 1, Step 2, Step 3, etc. layout. It is a very good starting point for a typical image analysis application. This application uses GUIDE to do the user interface design, and has most of the basic controls such as buttons, listboxes, checkboxes, radio buttons, scrollbars, etc. It allows the user to select a folder of images,................
Anyway, you could write the stuff out to a .mat file for your other GUI to read in, or check the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.3F

saharsahar
saharsahar 2012년 2월 6일
Thanks fo the information. but lets summerize my question. Since I am sending back the results in xxx_OutputFcn as follows:
s=get(handles.answer_edit,'String');
varargout{1} = s;
Then what I have to write in the"Load pushbutton". Do I need to write anything?
Thanks

Walter Roberson
Walter Roberson 2012년 2월 7일
Start with the Load uicontrol 'Enable' property set 'off', and have your Browse callback set the Load button's Enable to 'on' when it detects valid input. Watch out for the user canceling the uigetfile()
In the Load callback,
get(handles.answer_edit,'String')
and do whatever is appropriate with it.

saharsahar
saharsahar 2012년 2월 7일
Thanks for the sample code. I tried However still I am getting error. here is the codes which I have written.
in Opening Function:
function XXXAlgorithm_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
uiwait(handles.figure1);
in Output Function
function varargout = XXXAlgorithm_OutputFcn(hObject, eventdata, handles)
s=get(handles.load_button,'String');
varargout{1} = s;
In Browse Button:
function browse_button_Callback(hObject, eventdata, handles)
[FileName,FilePath]=uigetfile();
ExPath = [FilePath FileName];
set(handles.answer_edit,'String',ExPath);
guidata(hObject, handles);
in edit Text Button
function answer_edit_Callback(hObject, eventdata, handles)
answer_edit as a double
FilePath=get(handles,editFilePath,'String');
set(handles.editFilePath,'String',FilePath);
in Load Button:
function load_button_Callback(hObject, eventdata, handles)
t = get(handles.answer_edit,'String');
uiresume(XXXAlgorithm);
delete(XXXAlgorithm);
return;
Thanks if you let me know which part Im doing mistake. Thanks
  댓글 수: 1
Image Analyst
Image Analyst 2012년 2월 7일
In the load button, try
delete(handles.XXXAlgorithm);

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


Ka Mirul
Ka Mirul 2017년 11월 20일
편집: Walter Roberson 2018년 1월 28일
I found a video that help me, it is about creating GUI to browse an image and display the image and its name. It should help you : https://youtu.be/7EmFShs5y9I

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by