MATLAB: I have no experience with GUI. With Malab R2018a (App Designer) I would like to code a simple GUI, which adds two numbers. How can i display the result in an edit field

app designerMATLAB

The obective of this introductive GUI should be adding two numbers and displaying the resulting sum. This is what I coded so far:
a = struct2cell(get(app.EditField1));
a = a{1,1};
b = struct2cell(get(app.EditField2));
b = b{1,1};
c = a + b;
set(app.EditField3,c)
My GUI contains 3 (numeric) edit fields (one for 'a', one for 'b' and onde for the result 'c=a+b' and additionally a (calculation) button.
– Is there a simpler way to code it? – The code above does not work – the result is not displayed. How can I display the result in 'EditField'?
Thanks in advance.

Best Answer

You need to get the String property, convert form char to a numeric, compute the sum, convert to char and set the String property.
function ButtonPushed(app, event)
a = get(app.EditField1,'Value');
b = get(app.EditField2,'Value');
c = a + b;
set(app.EditField3,'Value',c)
end