Welcome! Log In Create A New Profile

Advanced

assigning variables in editable

Posted by lucast4 
assigning variables in editable
October 26, 2020 09:49AM
Hi Jaewon,
I noticed that editable requires passing in variables for which values have been directly assigned. For example:

This works fine:
    behfeat= [1 2 3];
    editable('behfeat');


However, this does not:
    values = [1 2 3];
    behfeat = values;
    editable('behfeat');

Traceback:
Error using eval
Unrecognized function or variable 'values'.

Error in embed_timingfile (line 47)
        val = eval(tokens{n}{1}{1});

Error in run_trial (line 55)
                runtime_handle{m,2} =
                get_function_handle(embed_timingfile(MLConfig,timingfile{m},trialholder));

Error in monkeylogic/UIcallback (line 862)
                    result = run_trial(MLConfig,datafile);
 
Error while evaluating UIControl Callback.

Thank you!
Re: assigning variables in editable
October 26, 2020 09:52AM
More generally, I would like to assign editable variables in cases where I do not need to pre-specify both the variable name and the values. Ideally something like:

list_of_strings = getVariableNames() % length-N cell array of strings
list_of_values = getValues() % length-N cell array, each element an numerical array of values
for i=1:length(list_of_strings)
  eval([list_of_strings{i} ' = [' num2str(list_of_values{i}) ']' ])
end
editable(list_of_strings{:});

Is this possible?
THanks
Re: assigning variables in editable
October 26, 2020 10:41PM
It should be determined before any timing script is executed which variables are editable, so they must be initialized with values (numbers or characters), not with other variables or return values of functions.
Re: assigning variables in editable
October 27, 2020 09:17AM
Is there any workaround for this? The problem is that I have parameters whose names and values vary from expt. to expt. There is no way for me to hard code those values.

Is the following an alternative: hard code those variables the same way always, but immediately in the first trial assign the correct values to these variables. And every trial read out those values appropriately?

Thanks
Re: assigning variables in editable
October 27, 2020 09:46PM
The variables have to be hard-coded. There is no workaround.

Of course, you can assign new values to them. But I wonder then what is the point of making them editable. Their values will be reset every session.
Re: assigning variables in editable
October 29, 2020 02:32PM
The idea is that each session might start with a unique set of values, but during that session I could update the values as needed (just for that session).

This way I have default values based on experimental parameters (which I specify for each session) but also the option to modify those parameters based on how the subject is performing.

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.