MATLAB Answers

Reading multiple editable text boxes.

조회 수: 1(최근 30일)
Jack Georege
Jack Georege 2021년 3월 30일
댓글: Jack Georege 2021년 4월 6일
So for a project that I am doing that requires programmatic GUI development, I am trying to write a program that can read single letter inputs from multiple editable text boxes and put them into an array to be used later on. I found some code posted by Walter Roberson in 2013 that successfully created the boxes using a for loop, but now i don't know how to read the inputs in the boxes.
Here is the part that creates the text boxes:
np1 = 5;
editp1 = zeros(np1,1);
for K = 1:np1
editp1(K) = uicontrol( 'Style', 'edit', 'Units', 'normalized', 'Position', [(0.1+((K-1)*0.04)) 0.7 0.04 0.07]);
end
How would i program a push button to write the inputs of the text boxes into an array at the push of said button? I know it will use a callback function but i have no idea what that would look like nor what outputs would go on the button code itself.

답변(1개)

Reshma Nerella
Reshma Nerella 2021년 4월 5일
Hi,
1. Create a property editFieldsArray in the app.
If you want to use a variable across the app, you need to declare it as an App property
properties (Access = private)
editFieldsArray;
noOfFields
end
2. Create an array of text/numeric editFields.
app.noOfFields = 5;
for i = 1 : app.noOfFields
tempArray = uieditfield(app.UIFigure, 'text', 'Position', [20, 400-i*20,100,22]);
end
app.editFieldsArray = tempArray;
3. Create a button in th App and add the corresponding 'Button pushed function' callback.
a. Click on the name of button in Component Browser
b. Select Callbacks tab
c. Create Button pushed function.
4. In the Button pushed function add the code for obtaining values from the EditFeilds and store in an array.
editFieldsValues = zeros(1, app.noOfFields);
for i = 1 : app.noOfFields
editFieldsValues(i) = convertCharsToStrings(app.editFieldsArray(i).Value);
end
Whenever the button is clicked, all the Values from the Edit Feilds will get stored in 'editFieldsValues' variable.
To know more, refer to the examples and documentation of App Designer: Examples
Hope this helps!
  댓글 수: 2
Jack Georege
Jack Georege 2021년 4월 6일
Like Rik said, I'm not using the AppDesigner. This is being made programmatically.

댓글을 달려면 로그인하십시오.

태그

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by