How to show path of file in GUI editbox?

4 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by