How to write the Text in Text Box using For Loop

I want to display the Channels # as from 1 to 32 at the Start up using for loop.
handles.text_ch = [];
for range = 1:32
set(handles.text_ch,'String',range);
end
But this command didn't work. Please guide me.

2 个评论

the question is a bit confusing. You want to develop someting similar to the one in image?
Yes . if you see the Channel# 1 2 3 ..............32. I want the following task:
If i select the Range Radio Button (1 32) Channel # would be displayed as 1 2 3 ........ 32
If i select the Range Radio Button (33 64) Channel # would be displayed as 33 34 ........ 64
If i select the Range Radio Button (65 96) Channel # would be displayed as 65 66 ........ 96
If i select the Range Radio Button (97 128) Channel # would be displayed as 97 98 ........ 128.
Means that with the Slection of Range Radio Button, The Channel Numbers change respectively.

请先登录,再进行评论。

回答(1 个)

Of course the shown code cannot work. By the way, prefer to pos the error message instead of the general statement "didn't work".
handles.text_ch = []; % Now handles.text_ch is teh empty matrix
for range = 1:32
% You cannot set the 'String' property of an empty matrix:
set(handles.text_ch, 'String', range);
end
You need to use the correct handles. I cannot guess, what the text_ch field of the handles struct is. If it is a vector of handles of text objects, use:
Offset = 0;
for range = 1:32
set(handles.text_ch(range), 'String', sprintf('%d', range + Offset * 32));
end
Now set the Offset to the index of the radio button.
Maybe handles.text_ch is something else. Then please mention, how it was created.

3 个评论

handles.text_ch is the tag name of the Channel numbers.
i run the above code. But its give the Error "Index exceeds array bounds"
I change the name of handle to the default name, as , handles.text.
Please help me in this error, Index exceeds array bounds.

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息

标签

提问:

2018-11-29

评论:

2018-11-30

Community Treasure Hunt

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

Start Hunting!

Translated by