uigetdir in a gui environment

조회 수: 11 (최근 30일)
Jules Ray
Jules Ray 2013년 5월 4일
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

채택된 답변

Walter Roberson
Walter Roberson 2013년 5월 4일
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
Walter Roberson
Walter Roberson 2013년 5월 4일
Sorry, the syntax is different than most other options.
save('terracem_path.mat', '-struct', 'structdata')
Jules Ray
Jules Ray 2013년 5월 4일
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')

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by