uigetdir in a gui environment
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
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 comentarios
Respuesta aceptada
  Walter Roberson
      
      
 el 4 de Mayo de 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 comentarios
  Walter Roberson
      
      
 el 4 de Mayo de 2013
				Sorry, the syntax is different than most other options.
save('terracem_path.mat', '-struct', 'structdata')
Más respuestas (0)
Ver también
Categorías
				Más información sobre Historical Contests en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!