Hello everyone! I am new to GUI in MATLAB and I need to write an analysis user interface. I am just starting out and the first step for the GUI is to let the user select the directory that contains the data files. This is the code so far:
% % --- Executes on button press in ChooseFolder.
function ChooseFolder_Callback(hObject, eventdata, handles)% hObject handle to ChooseFolder (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
folder = uigetdir('Search Folder Containing Data Files');if isequal (folder, 0); set(handles.DisplayFolderName, 'String', 'No folder selected'); set(handles.FileInputString, 'enable', 'off');else[~, name] = fileparts(folder); textLabel = sprintf('Selected folder is %s', name);set(handles.DisplayFolderName, 'String', textLabel);filePattern = fullfile(folder, '*.csv');allfiles = dir(filePattern);for k = 1 : length(allfiles); baseFileName = allfiles(k).name;endend
Now I want to add a Edit Text and Push Button. The Edit Text allows the user to enter the filename (for example): ID0123. Then, the Push Button can be pressed and MATLAB will look for this file in the before chosen directory. I have tried this:
% --- Executes on button press in findfile1.
function findfile1_Callback(hObject, eventdata, handles)% hObject handle to findfile1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)filename = get(handles.edit1, 'String');if exist (name, filename) csvread(filename);else warningMessage = sprintf ('Warning: file does not exist:\n%s' , filename); uiwait(msgbox(warningMessage)); end
But this does not do anything. Can anyone please help me with this issue?
Would be very much appreciated
Best Answer