Passing Data between Scripts and Functions

5 次查看(过去 30 天)
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