Hey guys,
I found where the problem is. In the field components on the GUI, default parameters are specified. However, the callback for each field components only executes if field values are changed. The variables can be added by clicking the green '+' button in the Properties tab (upper left). The code block for Properties are as follows:
properties (Access = public)
% Define all input and output variables
A; output
end
In my previous code, I've declared all properties as per above, and defined callbacks as well. Below is one of the many callback functions for field components, where I assigned the field values into the variable 'A'. Notice that in the comment, it says 'value changed function', i.e. this function is only executed if field value changes.
% Value changed function: IterationEditField
function IterationEditFieldValueChanged(app, event)
app.A = app.AEditField.Value;
end
However, I intended to have a default value in the field components until the user changes them, which means the code does not have instructions to extract default values (since the values are only extracted if the user changes them). Thus what I did was to include a 'startupFcn' code block, which executes when the whole GUI starts. The 'startupFcn' code block can be added by clicking '+' in the Callbacks tab (upper left), choose UIFigure in 'Components' and then startupFcn in 'Callback'.
% Code that executes after component creation
function startupFcn(app)
%Extract values from field components during startup
%if field values changed, callbacks in the following section will execute to extract values
app.A = app.AEditField.Value;
end
Lastly, in the 'pushbuttoncallback' function, I called the function from a m-file like usual.
% Button pushed function: RunButton
function RunButtonPushed(app, event)
%when push button is clicked
%declare global here for all input and outputs
global A
A = app.A;
%Run intended function from some m-file
[output] = YourFunctionName(A);
app.output = output;
end
Then you can assign the output into other a property just like in the code above.
Long story short, the program needs to extract values upon startup, since the callbacks for edit-field components are only for condition where the value is changed by the user.