Thread Subject: uigetdir in a gui

Subject: uigetdir in a gui

From: David Hsieh

Date: 9 Jul, 2008 18:45:04

Message: 1 of 9

I'm having a little trouble implementing a "browse button" in my gui. The button
should allow the user to select a directory and, after this is done, to return the
directory to an "edit text" box also in the gui, which in turn, returns the entire
string to my image analysis function.

Another "browse button" should perform the same function, only for an output
"edit text" box, so the user can select which directory to ouput the analysis file
into.

However, whenever I click on the browse buttons, nothing happens. No error
message or anything. Here is the code for the input browse button:

function input_browse_Callback(hInbrowse,eventdata,handles)
indir=uigetdir;
handles.input=char(indir)
function input_browse_CreateFcn(hInbrowse,eventdata,handles)

Subject: uigetdir in a gui

From: Donn Shull

Date: 9 Jul, 2008 19:16:02

Message: 2 of 9

If the edit box you want to place the directory text into
has the tag edit1 for example then replace the statement:

handles.input=char(indir);

with:

set(handles.edit1, 'String', indir);

to see your selected directory show up in the edit box.

Subject: uigetdir in a gui

From: David Hsieh

Date: 9 Jul, 2008 19:22:02

Message: 3 of 9

"Donn Shull" <donn.shull.no_spam@aetoolbox.com> wrote in message
<g532pi$jj2$1@fred.mathworks.com>...
> If the edit box you want to place the directory text into
> has the tag edit1 for example then replace the statement:
>
> handles.input=char(indir);
>
> with:
>
> set(handles.edit1, 'String', indir);
>
> to see your selected directory show up in the edit box.
>

Thanks Donn, but I also have the problem that when I click on the browse
button, the uigetdir box doesn't even appear. Nothing happens (I've checked
the tag links, too, and they match up).

Subject: uigetdir in a gui

From: Matt Fig

Date: 9 Jul, 2008 19:23:02

Message: 4 of 9

This example gui does some of what you want. I think you'll
get the idea.



function [] = mygui_s()
% The basic layout of this GUI was made with the help of
% guidegetter, available on the File Exchange at
% Mathworks.com

hf = figure('units','normalized','position',...
[0.3 0.5 0.3 0.1],...
'menubar','none','name',...
'mygui_s','numbertitle','off','color',...
    [0.831 0.816 0.784]);
edit1=uicontrol(hf,'style','edit','units','normalized',...
    'position',[0.1 0.5 0.8 0.4],'string','edit1',...
'backgroundcolor',...
    [1 1 1]);
pushbutton1 =
uicontrol(hf,'style','pushbutton','units','normalized',...
    'position',[0.1 0.1 0.8 0.2],'string','pushbutton1',...
    'backgroundcolor',[0.831 0.816 0.784],'callback',...
    {@input_browse_Callback,edit1});


function input_browse_Callback(hand,eventdata,edit1)
indir=uigetdir;
set(edit1,'string',indir)
set(hand,'userdata',indir)

Subject: uigetdir in a gui

From: David Hsieh

Date: 9 Jul, 2008 20:17:02

Message: 5 of 9

Thanks for all your help, but for some reason, my pushbuttons are still
unresponsive. The problem isn't so much that they're calling an erroneous
function, but that they aren't calling a function at all.

Subject: uigetdir in a gui

From: David Hsieh

Date: 9 Jul, 2008 20:28:34

Message: 6 of 9

I'm an idiot. I got it fixed.

Turns out I had set the tag for each browse button, but I hadn't typed anything
in the "callback" or "createfcn" zones.

Thanks for your help.

Subject: uigetdir in a gui

From: Donn Shull

Date: 9 Jul, 2008 20:45:05

Message: 7 of 9

Post your code nd I will have a look.

Subject: uigetdir in a gui

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 9 Jul, 2008 20:57:37

Message: 8 of 9

In article <g5371i$g2b$1@fred.mathworks.com>,
David Hsieh <dhsieh@indiana.edu> wrote:
>I'm an idiot. I got it fixed.

>Turns out I had set the tag for each browse button, but I hadn't typed anything
>in the "callback" or "createfcn" zones.

Sounds like you were using GUIDE or some other GUI constructor.
That would have been a useful fact for the problem-solvers to know.
--
  "I buy more from my grocer than he buys from me, and I bet it's
  the same with you and your grocer. That means we have a trade
  deficit with our grocers. Does our perpetual grocer trade deficit
  portend doom?" -- Walter Williams

Subject: uigetdir in a gui

From: Travis

Date: 2 May, 2009 03:54:02

Message: 9 of 9

I am having a similar problem (using GUIDE by the way). I have a "browse" button...

% --- Executes on button press in ExBrowse.
function ExBrowse_Callback(hObject, eventdata, handles)
% hObject handle to ExBrowse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileEx,PathEx] = uigetfile('*.xls','Select the Excitation Correction File');
ExPath = [PathEx FileEx];

handles.ExPath = ExPath;
guidata(hObject,handles);
set(handles.ExLoc,'String',ExPath);

and would like the path to be displayed in a text field that has its tag as ExLoc, but nothing appears in the field.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
uigetdir David Hsieh 9 Jul, 2008 14:50:19
gui David Hsieh 9 Jul, 2008 14:50:19
browse David Hsieh 9 Jul, 2008 14:50:19
callback David Hsieh 9 Jul, 2008 14:50:19
createfcn David Hsieh 9 Jul, 2008 14:50:19
handles David Hsieh 9 Jul, 2008 14:50:19
char David Hsieh 9 Jul, 2008 14:50:19
rssFeed for this Thread

Contact us at files@mathworks.com