필터 지우기
필터 지우기

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
Stephen23
Stephen23 2022년 5월 13일
"so I should do use the following code instead? "
Yes.

댓글을 달려면 로그인하십시오.

추가 답변 (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