Clear Filters
Clear Filters

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

1 view (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 29 Oct 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 Comments
Stephen23
Stephen23 on 4 Nov 2021
Edited: Stephen23 on 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 on 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).

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!