How to use data from base workspace in app designer application
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
1 vote
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
xi
on 1 May 2017
3 votes
initialize your EditFields using evalin(), such as: app.EditField1.Value=evalin('base','myvar1'); app.EditField2.Value=evalin('base','myvar2'); ...
8 Comments
Daan Decleer
on 2 May 2017
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
xi
on 2 May 2017
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;
Erik Vabo Vatsvaag
on 4 Nov 2020
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
Md Noor Islam
on 11 Nov 2020
@Adam Danz it's not working
Adam Danz
on 11 Nov 2020
"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?
Mark Sahlin
on 18 Apr 2022
using app designer it would not allow me access to edit in code view
Mark Sahlin
on 18 Apr 2022
the Code View for the initial EditField does not allow me to add a line to change the value via an evalin.
More Answers (0)
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
