How to write the Text in Text Box using For Loop
Show older comments
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.
Answers (1)
Jan
on 30 Nov 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.
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!