How can I avoid using addpath to read files outside Matlab's search folder?
조회 수: 5 (최근 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?
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Downloads에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!