Finding file in a before selected folder
4 ビュー (過去 30 日間)
古いコメントを表示
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;
end
end
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
2 件のコメント
Rik
2018 年 4 月 16 日
Another probable cause of problems is that the ChooseFolder callback doesn't seem to store all information in the guidata handle struct.
And why did you close this question?
採用された回答
Stephen23
2018 年 4 月 13 日
編集済み: Stephen23
2018 年 4 月 13 日
I looked at the exist help, but could not find any syntax that matches how you are using it. Probably you should read the documentation and use one of the supported syntaxes, e.g.:
if 2==exist(filename,'file')
Also the line:
csvread(filename);
reads some data and then discards it immediately.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Help and Support についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!