2
votes

I want to set a variable using matlab eval/feval function. It is possible to write the whole statement as a string and use = sign, but I want to pass the value as a separate argument (not in string).

The arithmetic operators in matlab have function equivalents, so the strings of these functions names can be used in eval and feval functions. Is there a function equivalent for the = operator?

The mechanism I am looking for would be like:

eval('set','x',5)

And I expect it to set value of the variable x to 5.

2
Can you give an example of what you are trying to do... even if the syntax is wrong. It will be easier to fix that, than try to guess from your description. - Floris
I am using matlab from java using the MatlabControl library. I can use eval/feval and by passing java typed arguments to the corresponding method, they will be converted to matlab types automatically. - Hassan
I edited my question as you said. - Hassan

2 Answers

3
votes

It seems like you are looking for something like assignin

2
votes

Since you said "It is possible to write the whole statement as a string", but you want part of the string to be passed in as a variable, would the following work:

evalString = sprintf("most of the string with %s a placeholder", extraArg);
variableToSet = eval(evalString);

In this way you create a string from a "variable component". Of course if extraArg isn't a string, you could convert it from whatever it was, with appropriate formatting.