How to import functions without addpath

5 ビュー (過去 30 日間)
adi hendel
adi hendel 2022 年 5 月 1 日
回答済み: Walter Roberson 2022 年 5 月 1 日
I have a main.m script that uses code from multiple folders. Is there a way to access files in those folders without addpath? I'm looking for something like Python, for example: import directory1.my_function
  1 件のコメント
Riccardo Scorretti
Riccardo Scorretti 2022 年 5 月 1 日
I'm not aware of something like that.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 5 月 1 日
scripts (but not functions) can be accessed using run() including a directory.
Functions must be on the path, or in a package or class on the path, or in the current directory or in a directory named "private" relative to current directory.
It is not possible to call a function that is not on the path.
A work-around can be to cd to the directory that contains the function, and use @ to take a handle to it and cd back. The handle records the path.

カテゴリ

Help Center および File ExchangeSearch Path についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by