Filter löschen
Filter löschen

I would like to use UIGETFILE function in order to search for any file from any path of my computer.

1 Ansicht (letzte 30 Tage)
Hello everyone.
I am new to MatLab, and I would like to know how can I make the program be able to look for any file from any folder of my computer not just the MATLAB folder containing the program.
Currently I am using UIETFILE function and it works if the file is in the MATLAB folder, but if I write the following in the code:
[Archivo, Direccion]=uigetfile({'*.xlsx','Data Files (.xlsx)','*.*','All Files (*.*)'});
I get the following error:
Error using readmatrix (line 158)
Unable to find or open 'Curva_Produccion_Parque.xlsx'. Check the path and filename or file permissions.
Thanks for the help.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 29 Okt. 2021
[Archivo, Direccion]=uigetfile({'*.xlsx','Data Files (.xlsx)','*.*','All Files (*.*)'});
if ~ischar(Archivo)
return; %user cancel
end
fullname = fullfile(Direction, Archivo);
data = readmatrix(fullname);
  5 Kommentare
Stephen23
Stephen23 am 4 Nov. 2021
Bearbeitet: Stephen23 am 4 Nov. 2021
"gives the correct answer for the fullname (Name+path) description as you can see:"
The error message clearly shows you have combined the filename and the filepath in the wrong order:
'Curva_Produccion_Parque.xlsx/-/Users/davidborga/... INICIAL/'
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^ filename
% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ filepath
All OS's in common use have the filename at the RHS end of the path (just as Walter Roberson showed you).
David Borrego
David Borrego am 4 Nov. 2021
Indeed it was my mistake changing filepath for filename.
Thank you so much for your help (and sorry to Walter whose answer was perfect).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by