How can I avoid using addpath to read files outside Matlab's search folder?

9 次查看(过去 30 天)
I am working on developing an app using Matlab's app desiger. The app will be used as a stand alone application on a different computer and reads excel files and does some calculations. The path of the excel file is given by the user. The commad behind this step is
file=uigetfile('*.xlsx')
Is it correct that before files can be read by Matlab, the folder where files are located have to be added to Matlab's search folder using:
addpath(genpath('directory'))
Some of the excel files that will be used in this app are in folders on a network and I've noticed they can't be added to Matlab's search folder or at least this doesn't work using app designer. Is there any way to read these files without having to add their directory to Matlab's search folder?

采纳的回答

Stephen23
Stephen23 2022-5-13
编辑:Stephen23 2022-5-13
" Is it correct that before files can be read by Matlab, the folder where files are located have to be added to Matlab's search folder using: "
No, that is incorrect. The search path is for MATLAB code, not for accessing datafiles.
I strongly recommend not adding folders of datafiles to the MATLAB path, it will slow down MATLAB.
The simple and efficient approach to access datafiles is to use absolute/relative filenames. MATLAB functions that import/export/read/write datafiles accept relative/absolute filenames. You will find FULLFILE very useful for that.
"Is there any way to read these files without having to add their directory to Matlab's search folder?"
Absolute/relative filenames. MATLAB should be able to access any file that is available to the user running MATLAB.
Note that you probably want UIGETFILE to return its second output, otherwise you will have a lot of difficulties.
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by