uigetdir in a gui environment
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
2013-5-4
Sorry, the syntax is different than most other options.
save('terracem_path.mat', '-struct', 'structdata')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!