Error in the Code shown below:

handles.text_ch = []; % Vector of the Test Fields
Offset = 0;
for range = 1:32
set(handles.text_ch(range), 'String', sprintf('%d', range + Offset * 32));
end
Error is:
Index exceeds array bounds.
Error in GUI_OpeningFcn (line 122)
set(handles.text_ch(range), 'String', sprintf('%d', range + Offset * 32));
Please help me.

回答 (1 件)

Guillaume
Guillaume 2018 年 11 月 30 日

0 投票

Isn't the error obvious? You defin handles.text_ch as an empty array and then try to access its elements 1 to 32. Since it's empty it doesn't even have an element at index 1.
Put at least 32 elements in that handles.text_ch variable. Note that these 32 elements should be some sort of uicontrol.

4 件のコメント

Mohsin
Mohsin 2018 年 11 月 30 日
Please tell me .. whats that mean that these 32 elements should be some sort of uicontrol?
Guillaume
Guillaume 2018 年 11 月 30 日
Isn't this your code? How come you don't understand what it does?
Clearly, the line:
set(handles.text_ch(range), 'String', sprintf('%d', range + Offset * 32));
is intended to change the String property of a uicontrol (or similar item).
Mohsin
Mohsin 2018 年 11 月 30 日
Yes this string will change the unicontrol property. But how can i initialize the handles.text_ch variable, other then []. I didn't get the point.
Guillaume
Guillaume 2018 年 11 月 30 日
編集済み: Guillaume 2018 年 11 月 30 日
The code you show is meant to change the String property of 32 different UI controls. Hence you need to put the handle of 32 UI controls into handle.text_ch. How you do this, I can't tell you since I've no idea how you create these 32 controls in the first place. If you create them in code, put their handle in handle.text_ch when you create them.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

質問済み:

2018 年 11 月 30 日

編集済み:

2018 年 11 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by