Hello Ashok,
When you create a component in MATLAB App Designer and later delete it, the callback function associated with that component may not automatically be removed from the code. This is why the callback function remains even after you delete the component.
Why the Callback Function Remains
- Manual Removal: When you delete a component, MATLAB does not automatically remove the associated callback functions. You need to manually remove the callback function code from your app.
- Code Consistency: MATLAB assumes that you might still need the callback function for some other purpose or might want to reassign it to another component.
When you insert a new ‘EditField’ numeric component, MATLAB does not automatically generate a new callback function if there is already an existing callback function with the same name. You need to manually assign or create a new callback function for the new component.
To use the numeric value in another function in the app, you need to store the value as a property. Please follow these steps to add a new property and change its value during a callback:
- Define a Property: Define a property in your app to store the numeric value.
- Update the Property: Update this property in the callback function of the ‘EditField’ numeric component.
- Access the Stored Value: Access the stored value in the callback function of another component.
Here is a code snippet that highlights how to add a new property, change its value, and use it in another callback:
classdef MyApp < matlab.apps.AppBase
properties (Access = public)
UIFigure matlab.ui.Figure
EditFieldNumeric matlab.ui.control.NumericEditField
AnotherComponent matlab.ui.control.Button
properties (Access = private)
methods (Access = private)
function EditFieldNumericValueChanged(app, event)
app.NumericValue = app.EditFieldNumeric.Value;
function AnotherComponentPushed(app, event)
disp(['The numeric value is: ', num2str(app.NumericValue)]);
For further understanding, kindly refer to the following MathWorks Documentation:
I hope you find the above explanation and suggestions useful!