how to take input from created edit fields in app designer
조회 수: 16 (최근 30일)
이전 댓글 표시
I have created Edit Fields in the interface, but I have no idea how to store values from the created EditFields.
Example: when I enter n as 2 and press button, It creates 2 edit fields, code is as follows.
% Button pushed function: Button
function ButtonPushed(app, event)
n=app.nEditField.Value;
for i = 1:n
app.EditFields=uieditfield(app.UIFigure,'text','Position',[100 350-20*i 150 20],'Placeholder',sprintf('Enter number '));
end
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1070370/image.png)
After entering the values in editfields and pushing the button2, The values must be store in a cell.
댓글 수: 0
채택된 답변
Image Analyst
2022년 7월 19일
편집: Image Analyst
2022년 7월 19일
I don't suggest you create them on the fly. I suggest you just create them all with known names in advance. Just set their visible property to hidden/off. Then (in the button callback if you wish) you can use a switch or if to make all visible up until the nth box and invisible after that. Then since you know their names, you can easily get the contents just like you did for n.
Attach your .mlapp file if you need more help, after you read this:
추가 답변 (1개)
Monica Roberts
2022년 7월 19일
One problem is that you aren't storing the handles to the edit fields as separate entities. As you loop, "app.EditFields" is being overwritten, so you only have access to the latest one. But in general, to access the value, you can reference the value:
app.EditFields.Value
It looks like you may want to check out this answer:
https://www.mathworks.com/matlabcentral/answers/373094-edit-field-labels-and-edit-field-numeric-loop
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!