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 comentarios

Preethi
Preethi el 30 de Nov. de 2018
the question is a bit confusing. You want to develop someting similar to the one in image?
Mohsin
Mohsin el 30 de Nov. de 2018
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.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 30 de Nov. de 2018
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 comentarios

Mohsin
Mohsin el 30 de Nov. de 2018
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"
Mohsin
Mohsin el 30 de Nov. de 2018
I change the name of handle to the default name, as , handles.text.
Mohsin
Mohsin el 30 de Nov. de 2018
Please help me in this error, Index exceeds array bounds.

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Properties en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 29 de Nov. de 2018

Comentada:

el 30 de Nov. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by