How to show path of file in GUI editbox?
2 次查看(过去 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.
0 个评论
采纳的回答
Walter Roberson
2016-6-9
S3.selected_dir_upload = fullfile(Pathname1, FileName1);
4 个评论
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 Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!