views:

307

answers:

2

I have a variable in the MATLAB workspace and I want to pass the variable name and its contents to a function in my GUI.

How do I achieve this task?

+1  A: 

I'm not totally sure what you mean when you say "pass the variable name and its contents", but here's one possible solution. After you pass a set of data to a function like so:

some_function(data);  %# Pass the variable "data" to a function

You can get the variable name of the input argument from inside the function using INPUTNAME:

function some_function(inputArgument)
  name = inputname(1);  %# Will return "data" as the name of the input variable
end

EDIT: As pointed out in a comment by High Performance Mark, the variable inputArgument inside the function will contain the values stored in the variable data in the workspace of the caller.

gnovice
and the value of the passed variable is passed to become the value of the dummy argument, in this case inputArgument. Just in case that wasn't obvious.
High Performance Mark
Thank you all, I found a way of passing the variable to a function using eval
Tim
A: 

If this question is related to your other most recent question, then why not build the operation into your GUI? You can use guide to create a pushbutton, and place the code under the callback function.

Doresoom