Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change 'Var' function of assignin based on user input

Tags:

matlab

I'm trying to write a GUI in MatLab that enables me to take the data it is outputting and move it to the work-space. I'm currently achieving this with the assigning function but what I would like to happen is have the name of the variable change depending on what the user inputs in a edit box

Here is my current script:

function Save_Callback(hObject, eventdata, handles, vavargin)

a=str2num(get(handles.VariableA,'String'));
b=str2num(get(handles.VariableB,'String'));    
c=str2num(get(handles.VariableC,'String'));    
d=str2num(get(handles.VariableD,'String'));

regionname=(get(handles.RegionName,'String'));

assignin('base','regionname' ,[a;b;c;d]);

Every time the save button is pressed it just calls it region name instead of grabbing the user inputted text.

Does anybody have any ideas? Since I'm fairly new to MatLab, please try to make the explanation as simple as possible.

like image 466
Endless Avatar asked Dec 01 '25 03:12

Endless


1 Answers

Leave off the quotes around regionname when you run the assignin command, as follows. Then it will use the value inside the variable regionname as the new variable name.

assignin('base', regionname ,[a;b;c;d]);
like image 178
Bob Gilmore Avatar answered Dec 02 '25 20:12

Bob Gilmore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!