MatLab App Design — how to use default value for Edit Field function?

Technical Source
2 min readNov 18, 2023

--

Hello,

I have an Edit Field box on the Design view and I opened a callback in the Code View. There is a default value in the Edit Field box that I would like to be used automatically when a user runs the app.

I have this:

% Value changed function: LengthEditField
function LengthEditFieldValueChanged(app, event)
app.L = app.LengthEditField.Value;
if isempty(app.L)
new_value = 3; % set default value to 3
end
app.L=new_value;
end

But when I use this variable in an equation, it tells me that its “empty (0x0) double”.

How do I get it to display a value of 3 for example ?

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

The code you have shared is for capturing the value in the edit field, not setting it. Also, keep in mind that callback functions only execute when they are called (typically by the user interacting with the component).

Therefore, the best way to set a default value for a component is through its properties in the Component Browser.

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet