How do I write into my m-file to use the GUI user-selected pathdirectory?

I have an interface (built using GUIDE) that gets the user to select a pathdirectory/file where jpegs images are kept. A pushbutton is then to be used to run an m-file using these images.
My question is how do i write into my m-file that i want the user-selected pathdirectory as the chosen directory and not the one I have so far manually written into the m-file (which I have so far run as a standalone program and not used through an GUI interface)?
Any help and advice would be gratefully appreciated - I am very new to this GUI programming.
Many thanks, Sue x

Answers (1)

folder_name = uigetdir(start_path,dialog_title)

4 Comments

Thanks but sorry to sound really stupid, where do I put this code? In my m-file or somewhere in the uicontrols of the pushbutton etc?
if you just need the folder name in the m-file put the code there just like you have done for the default folder, if you want the GUI to know it than you put the code to select the directory in the GUI, save the folder_name to the handles structure of the GUI and turn the m-file into a function that receives the folder_name as argument
I understand the theory behind what you are saying but unfortunately I do not understand the practice behind it.
% --- Executes on button press in extract_fp_test_images.
function extract_fp_test_images_Callback(hObject, eventdata, handles)
% hObject handle to extract_fp_test_images (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
This is what is in the callback function for the button at the moment. If I add:
directory = uigetdir;
set(handles.edit1,'string',directory);
Will this select the pathname that the user has selected on another pushbutton? But how do I get this directory into the m-file exactly?
turn the m-file into a function, for example
function ExtractImages(directory)
%original m-file code
end %it's the end of the function, not really required
After saving the function you can call it inside your GUI
% --- Executes on button press in extract_fp_test_images.
function extract_fp_test_images_Callback(hObject, eventdata, handles)
% hObject handle to extract_fp_test_images (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
This is what is in the callback function for the button at the moment. If I add:
directory = uigetdir;
set(handles.edit1,'string',directory);
ExtractImages(directory)

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Asked:

Sue
on 4 Jul 2011

Community Treasure Hunt

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

Start Hunting!