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

3 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2021-10-29
[Archivo, Direccion]=uigetfile({'*.xlsx','Data Files (.xlsx)','*.*','All Files (*.*)'});
if ~ischar(Archivo)
return; %user cancel
end
fullname = fullfile(Direction, Archivo);
data = readmatrix(fullname);
  5 个评论
Stephen23
Stephen23 2021-11-4
编辑:Stephen23 2021-11-4
"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 2021-11-4
Indeed it was my mistake changing filepath for filename.
Thank you so much for your help (and sorry to Walter whose answer was perfect).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by