フィルターのクリア

Getting access of an output variable from a function or script which is saved in a different folder.

1 回表示 (過去 30 日間)
Hi everybody, In one folder (P:\MATLAB\SystematischesPM\Data) I have got a script named "DataDownload". It returns a cell 20x1 named "DataSet".
My question: I would like, from another folder (Q:\SystematischesPM\Quality), to create a function which loads some of the data from the cell "DataSet".
I suppose that I will have to run the script "DataDownload" first from the function in (Q:\Syste...) and then get access to the desired data in "DataSet"? Do you know an elegant way of doing that?
  2 件のコメント
Stephen23
Stephen23 2018 年 9 月 5 日
"I have got a script named "DataDownload". It returns a cell 20x1 named "DataSet"."
Scripts do not have input or output arguments, so a script cannot return anything:
Do you have a script or a function? This makes a difference, as they can be called in different ways.
BdS
BdS 2018 年 9 月 5 日
Sorry for the confusion. I have got a script. When I run it I get a cell 20x1

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

回答 (1 件)

OCDER
OCDER 2018 年 9 月 5 日
Use path to define functions that you want to use, but are in different folders.
For your case,
addpath('P:\MATLAB\SystematischesPM\Data');
addpath('Q:\SystematischesPM\Quality')
In case you want to add subfolder too, use genpath
addpath(genpath('P:\MATLAB\SystematischesPM\Data'));
addpath(genpath('Q:\SystematischesPM\Quality'))
Now you can summon DataDownload from any working directory.
  1 件のコメント
OCDER
OCDER 2018 年 9 月 5 日
Why not turn your script into a function?
function Out = DataDownload()
Out = cell(20, 1);
...
Then you can get your cell from any function like:
function Out = myFunc(varargin)
MyData = DataDownload; %Gets your 20x1 cell from DataDownload.m function file
...
Of course, DataDownload must be added to your matlab path, as shown in the answer above.

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

カテゴリ

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