how to have variables from one file automatically read into another file

6 次查看(过去 30 天)
I have variables in file1.m that I want to be automatically transferred to an equation in file2.m. Ive tried using the load tool but keep coming up short. Any way to transfer the variables smoothly?
  2 个评论
Pablo Garcia
Pablo Garcia 2018-11-1
something I forgot to add, the variables in file1.m ask for the values of the variables, so the variables don't have a specific value and must be inputed by the user
Stephen23
Stephen23 2018-11-2
编辑:Stephen23 2018-11-2
"Any way to transfer the variables smoothly?"
Of course, just use input/output arguments, exactly as the function help shows. This is the simplest and most efficient way to transfer data from one function workspace to another.

请先登录,再进行评论。

回答(1 个)

TADA
TADA 2018-11-1
without knowing more details Ill have to assume its probably best to wrap your code in file2.m with a function that takes in those varriables as input
next simply call it from file1.m after you get the user input and have everything ready
or the other way arround and put the interaction with the user in a function which returns those varriables as output arguments, then you can call that function from your file2.m

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by