uigetdir in a gui environment

12 views (last 30 days)
i'm preparing a gui that consist in three buttons, two of these buttons select two directories and the third one save the paths in .mat file
i've been trying for hours to fix the script, but i have no experience in matlab gui's..... the idea is to obtain the paths and put these path into a .mat file (called terracem_path.mat).
until now this is what i get:
%%button 1 (maindir)
% --- Executes on button press in maindir.
function maindir_Callback(hObject, eventdata, handles)
% hObject handle to maindir (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Retrieve GUI data (the handles structure)
handles = guidata(hObject)
dir1=uigetdir(pwd,'Set the path to script files')
handles.maindir=char(dir1);
% Update handles structure
guidata(hObject, handles);
%%button 2 (stationsdir)
% --- Executes on button press in stationsdir.
function stationsdir_Callback(hObject, eventdata, handles)
% hObject handle to stationsdir (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject)
dir2=uigetdir(pwd,'Set folder with stations files')
handles.stationsdir=char(dir2);
% Update handles structure
guidata(hObject, handles);
%%button 3 (pushbutton5)
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%addpath(handles.maindir)
msgbox('Station dir path defined')
structdata=struct('terracem_dir','handles.maindir','stationsdir','handles.stationdir');
save('terracem_path.mat','structdata')
the pop ups windows are executing well, and opens and let me select the directories, however i can not save the paths of the directories in the final .mat file......
please if somebody have an idea will be really appreciated... i`m stuck in this issue since hours....
cheers

Accepted Answer

Walter Roberson
Walter Roberson on 4 May 2013
structdata = struct('terracem_dir', handles.maindir, 'stationsdir', handles.stationdir);
Question: Do you want the information saved as a structure, or do you want the information saved as the separate variables 'terracem_dir" and 'stationsdir' ? If you want separate variables then use
save('terracem_path.mat', 'structdata', '-struct')
  3 Comments
Walter Roberson
Walter Roberson on 4 May 2013
Sorry, the syntax is different than most other options.
save('terracem_path.mat', '-struct', 'structdata')
Jules Ray
Jules Ray on 4 May 2013
fantastic...¡¡¡ is finally working perfect now.. thanks a lot Walter...
here is the final code:
if true
% code
end
%%button 1 (maindir)
% --- Executes on button press in maindir.
function maindir_Callback(hObject, eventdata, handles)
% hObject handle to maindir (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Retrieve GUI data (the handles structure)
handles = guidata(hObject)
dir1=uigetdir(pwd,'Set the path to script files')
handles.maindir=char(dir1);
% Update handles structure
guidata(hObject, handles);
%%button 2 (stationsdir)
% --- Executes on button press in stationsdir.
function stationsdir_Callback(hObject, eventdata, handles)
% hObject handle to stationsdir (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject)
dir2=uigetdir(pwd,'Set folder with stations files')
handles.stationsdir=char(dir2);
% Update handles structure
guidata(hObject, handles);
if true
% code
end
%%button 3 (pushbutton5)
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%addpath(handles.maindir)
msgbox('Station dir path defined')
structdata = struct('terracem_dir', handles.maindir, 'stationsdir', handles.stationsdir);
save('terracem_path.mat', '-struct', 'structdata')

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!