Is it possible to change the value of 100 edit field(4 are text 96 are numeric) UI objects without having to write code for each one of them to clear their contents. I'm using the default names EditField_1 to 100.

댓글 수: 1

Stephen23
Stephen23 2018년 10월 25일
편집: Stephen23 2018년 10월 25일
" I'm using the default names EditField_1 to 100."
Ugh, this is such bad code design (not your fault, apparently this is just how appDesigner and GUIDE work). If you had simply written your own code (which I would recommend doing), then you could have just put all of those handles into one array H, and then all you would need is one set call:
set(H,'String','')
set even lets you set each object to a different value, read its help for more information.

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

 채택된 답변

Jan
Jan 2018년 10월 24일

0 개 추천

for k = 1:100
H = handles.(sprintf('EditField_%d', k));
set(H, 'String', sprintf('%g', rand));
end
I guessed you are working with GUIDE. It is not clear, which strings you want to insert. What is a "text" or "numeric" edit field? All these fields contain characters.

댓글 수: 4

In appdesigner you can choose between numeric and text edit Fields. They both use uieditfield, which can be set to numeric.
fig = uifigure;
edt = uieditfield(fig,'numeric');
Numeric edit fields do not accept strings as input and have a default value of 0 (they can not be empty). I think text fields are left-aligned and numeric fields are right-aligned. There might be more differences that i am not aware of. Personally i prefer to use only text edit fields.
Jan's approach will work for uieditfields aswell, however you need to change 'String' to 'Value'.
I should have mentioned i'm using appdesigner. When creating a UI one of the avvailable components is an Edit Field component with which acts as data a input or displayed. The line of code: H =handles.(sprintf('EditField_%d', k)); returns the error undefined variable "handles" or class "handles.EditField_1". I assume this would have worked with GUIDE.
in appdesigner your handles are stored in app rather than in handles.
for k=1:100
H=app.(sprintf('EditField_%d',k)); %is there really a _ ?
if strcmp(get(H,'Type'),'uieditfield')
set(H,'Value','hi')
else
set(H,'Value',2)
end
end
Check the name of your first edit field, it might be EditField rather than EditField_1.
Thanks this worked.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2018년 10월 24일

댓글:

2018년 10월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by