フィルターのクリア

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.
ardeshir moinian
ardeshir moinian 2022 年 5 月 13 日
Perfect! Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop 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