get data from workspace

1 visualización (últimos 30 días)
Frank
Frank el 19 de Feb. de 2012
I have some data in the workspace currently. Now i am writing a m function which needs these data. How can I get it? it always show that undefined coefficient.

Respuestas (1)

Oleg Komarov
Oleg Komarov el 19 de Feb. de 2012
A "standard" function could be considered a black box where you throw data in and get something out of it.
Once you defined the mechanism of the black box, you give it some data:
foo([1 2 3])
ans =
3
If you need the data to test your function there are several ways of doing that:
  • the simplest but dangerous way is to name the data in your workspace the same as your variables in your function and run it as a script (line by line).
  • the methodic way is to edit run configurations for the function (next to the green play icon)
  • the most straightforward is to call the function after you saved it.
If you have to use that specific data all the time, then hardcode it.
Evalin can throw variables in your function workspace from the base workspace. I never used the function except from educational purposes and I discourage you to do so.
Else, is hard to imagine what you're trying to accomplish w/o additional details.

Categorías

Más información sobre Scope Variables and Generate Names en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by