필터 지우기
필터 지우기

Passing Data between Scripts and Functions

조회 수: 5 (최근 30일)
Coopinator
Coopinator 2015년 4월 16일
답변: Stalin Samuel 2015년 4월 16일
Hello,
I have a simple question about loading data into functions. Right now I have a script that executes several functions that I have written. These functions require data from a structure array that I have saved as a .m file. Ideally, the conceptual flow of the script that I am trying to achieve is:
(1) load data from .m file
(2) execute function1()
(3) execute function2()
(4) execute function3()
(5) return output
Thus, I would load the data once in the script and then all of the functions could use it. Right now the script does not work like this, presumably because of some issue with the scope of the variables. The script works fine if I load the data in each function individually, but this is cumbersome and not very flexible. Ultimately I would like to add user input to the script such that the user selects which data set to load once and then all the functions refer to this data set. Thanks in advance.

채택된 답변

Stalin Samuel
Stalin Samuel 2015년 4월 16일
1) load data from .m file
(2) out1 = function1(arg11,arg12) %arg11,arg12 are the data from file which used within function 1
(3) out2 = function2(arg21,arg22)%arg21,arg22 are the data from file which used within function 2
(4) out3 = function3(arg31,arg32)%arg31,arg32 are the data from file which used within function 3
%%out1,out2,ou3 are function outputs

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by