How to use data from base workspace in app designer application

Hello
In my app designer program I have several Numeric Edit Fields, I would like to set them to the already declared variables before in the base workspace when my application opens.
Is there a way I can load the existing Variable and put them in the already existing EditField?
Thanks already, I look out to your answers.

 Accepted Answer

initialize your EditFields using evalin(), such as: app.EditField1.Value=evalin('base','myvar1'); app.EditField2.Value=evalin('base','myvar2'); ...

8 Comments

Thanks for your answer Xi!
Can you solve the DropDowns in the same way? If I initialize the DropDown with a String (which is one of it's possibilitys) will it work?
Best Regards
For example, if you have mystring={'A','B','C'}; in the workspace,
you can set the DropDown.Items in the startup function of app.
S=evalin('base','mystring');
app.DropDown.Items=S;
Check out this demo that shows how to produce a UITable that lists all variables in the workspace, their size, and class, and allows the user to use a checkbox to select which variables should be loaded into the app.
200208 171846-.png
Hello,
How to I change the value of the variable in the workspaced using the value in the edit field.
I have the following code and whenever I change the value of the edit field I get the following error:
Error using app1/ValueEditFieldValueChanged (line 53)
Error: Incorrect use of '=' operator. To assign a value to a variable, use '='. To compare values for equality, use
'=='.
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 378)
Error while evaluating NumericEditField PrivateValueChangedFcn.
Any help?
Thank you
function startupFcn(app)
app.vars = evalin('base', 'whos');
cell_array = cell(size(app.vars));
for i=1:length(app.vars)
cell_array{i} = app.vars(i).name;
end
app.DropDown_2.Items = cell_array;
app.variable = app.vars(1).name;
app.ValueEditField.Value = evalin('base', app.vars(1).name);
end
% Value changed function: DropDown_2
function DropDown_2ValueChanged(app, event)
app.variable = app.DropDown_2.Value;
app.vars = evalin('base', 'whos');
cell_array = cell(size(app.vars));
for i=1:length(app.vars)
cell_array{i} = app.vars(i).name;
%app.ValueEditField.Value = app.vars(i).value;
end
app.DropDown_2.Items = cell_array;
app.ValueEditField.Value = evalin('base', app.variable);
end
% Value changed function: ValueEditField
function ValueEditFieldValueChanged(app, event)
app.varvalue = app.ValueEditField.Value;
app.vars = evalin('base', [app.variable,' = ',num2str(app.varvalue),';']);
end
"It's not working" doesn't convey the problem and usually means that the user couldn't figure out how to implement the solution. What's not working? What did you try? What symptoms are you having that indicates there's a problem?
using app designer it would not allow me access to edit in code view
the Code View for the initial EditField does not allow me to add a line to change the value via an evalin.

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Asked:

on 1 May 2017

Commented:

on 18 Apr 2022

Community Treasure Hunt

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

Start Hunting!