MATLAB Answers

0

How to save the input of an edit text box on GUI?

Asked by Adam Luckman on 9 Dec 2018 at 0:30
Latest activity Answered by Cris LaPierre on 9 Dec 2018 at 3:27
I want to have the user input their first value into the edit box, click the save button (saving the input to an array) and then for them to be able to reinput another value in the same box and then that value also being saved in to the array. I want them to be able to do this as many times as they want until they click the calculate button of which a static box will show them the sum of this array.
I cannot seem to figure out how to set up the array inside the callback, as when i try i usually get: 'Array indices must be positive integers or logical values.' Error.

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Cris LaPierre on 9 Dec 2018 at 3:27
 Accepted Answer

Create a property for storing the values. You don't have to assign it a value, just name it. I named mine "nums"
properties (Access = private)
Nums; % Description
end
Add a callback to your edit field for when the value changes. Create your array by appending the current number to your property variable. This adds it to the top, but you can code this however you want.
% Value changed function: EditField5
function EditField5ValueChanged(app, event)
value = app.EditField5.Value;
app.Nums = [value; app.Nums];
end

  0 Comments

Sign in to comment.