フィルターのクリア

Help on Disappearing Popupmenu

5 ビュー (過去 30 日間)
Franco
Franco 2014 年 7 月 14 日
コメント済み: Franco 2014 年 7 月 14 日
So I've created a GUI with a popupmenu, but it seems that whenever I try to populate the menu, it disappears, anyone know what going on. Thanks in advance. Heres an example of what I am trying to do.
var1 = {'Ex1','Ex2','Ex3'}
for i =1:length(var1)
set(handles.popupmenu1,'String',var1(i),'Value',i)
end

採用された回答

Image Analyst
Image Analyst 2014 年 7 月 14 日
That code you gave will give you a single item (the last one) in the popup. Do not use a for loop. The items in a popup or listbox are not entered in one at a time like you tried, they are done all at once with a single call to set the string property. What you did was to set the entire list to just a single item, and you did it 3 times (once on each iteration of your for loop). Since there is only one item in there, and the value is now 3 (which is more than 1), the popup will not display.
To fix, send in all the items in one shot, then set the value.
var1 = {'Ex1', 'Ex2', 'Ex3'}
set(handles.popupmenu1, 'String', var1); % Send in all 3 items at once.
set(handles.popupmenu1, 'Value', length(var1)); % Set what item is selected (the last one).
  1 件のコメント
Franco
Franco 2014 年 7 月 14 日
That did it. Thanks buddy. Ive literally been working on this problem since last thursday. Thanks again!

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

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 7 月 14 日
編集済み: Azzi Abdelmalek 2014 年 7 月 14 日
Why the for loop?
var1 = {'Ex1','Ex2','Ex3'}
i=1
set(handles.popupmenu1,'String',var1,'Value',i)
  4 件のコメント
Franco
Franco 2014 年 7 月 14 日
Ive checked and debug everything. var 1 is being set, the value is being changed, but its not doing the trick. I would post the code, but its too extensive.
Image Analyst
Image Analyst 2014 年 7 月 14 日
Azzi's code is correct. If it doesn't work, then do it in two separate steps, set the string first, and then the value. Do not use a for loop. The items are not entered in one at a time like you tried, they are done all at once with a single call to set the string property.

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

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by