Azzera filtri
Azzera filtri

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

9 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Stephen23
Stephen23 il 13 Mag 2022
Modificato: Stephen23 il 13 Mag 2022
" 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 Commenti

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by