How to show path of file in GUI editbox?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
adi kul
am 9 Jun. 2016
Kommentiert: Walter Roberson
am 10 Jun. 2016
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 9 Jun. 2016
S3.selected_dir_upload = fullfile(Pathname1, FileName1);
4 Kommentare
Walter Roberson
am 10 Jun. 2016
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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!