How to show path of file in GUI editbox?

9 ビュー (過去 30 日間)
adi kul
adi kul 2016 年 6 月 9 日
コメント済み: Walter Roberson 2016 年 6 月 10 日
Hello All, I am facing an issue with uigetfile. What I have is a button "Upload" along with a edit box which supposed to be showing the path of the uploaded file. Here is what I tried:
%--- Executes on button press in upload.
function upload_Callback(hObject, eventdata, handles)
% hObject handle to upload (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName1,PathName1] = uigetfile({'*.txt';'*.csv';'*.*'},'Select the text file that contains the data');
if isempty(FileName1)
errordlg('No file was selected that contains the data so the calculation was aborted.');
flag = true;
return
end
% text file should consist of two columns,
fid = fopen(fullfile(PathName1,FileName1));
if fid == -1
errordlg('The file selected could not be read so the calculation was aborted.');
flag = true;
return
end
d = textscan(fid,'%f %f');
fclose(fid);
S3.fValues = d{1} % data1
S3.rValues = d{2} % data2
S3.selected_dir_upload =[Pathname1,FileName1];
handles.S3.selected_dir_upload =S3.selected_dir_upload ;
guidata(hObject, handles);
set(handles.upload_edit, 'String', S3.selected_dir_upload)
set(handles.upload, 'UserData', S3);
I am not able to set the path in edit box. Your help is much appreciated.

採用された回答

Walter Roberson
Walter Roberson 2016 年 6 月 9 日
S3.selected_dir_upload = fullfile(Pathname1, FileName1);
  4 件のコメント
adi kul
adi kul 2016 年 6 月 10 日
Did the same and getting that error there only!
Walter Roberson
Walter Roberson 2016 年 6 月 10 日
function upload_Callback(hObject, eventdata, handles)
% hObject handle to upload (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName1, PathName1] = uigetfile({'*.txt';'*.csv';'*.*'},'Select the text file that contains the data');
if isempty(FileName1)
errordlg('No file was selected that contains the data so the calculation was aborted.');
return
end
filename = fullfile(PathName1, FileName1);
% text file should consist of two columns,
fid = fopen(filename);
if fid == -1
errordlg('The file selected could not be read so the calculation was aborted.');
return
end
d = textscan(fid,'%f %f');
fclose(fid);
S3.fValues = d{1} % data1
S3.rValues = d{2} % data2
S3.selected_dir_upload = filename;
handles.S3.selected_dir_upload = S3.selected_dir_upload;
guidata(hObject, handles);
set(handles.upload_edit, 'String', S3.selected_dir_upload)
set(handles.upload, 'UserData', S3);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by