How to assign a default in a GUI?

1 回表示 (過去 30 日間)
Meshooo
Meshooo 2014 年 1 月 22 日
コメント済み: Image Analyst 2014 年 1 月 23 日
Dear all,
I am building a GUI and at one button function I want to import a string from a popup menu. However, if the user didn't chose any string from the popup menu then 'gray' should be set as a default. I wrote it like this
colormap_label = handles.colormap_label; % import the color map effect type from the popup menu
if isnan(colormap_label)
colormap_label = 'gray'
end
this code have an error message "Reference to non-existent field 'colormap_label".
Any one knows how to solve that?
Regards, Meshoo

採用された回答

Image Analyst
Image Analyst 2014 年 1 月 22 日
編集済み: Image Analyst 2014 年 1 月 22 日
Load up your popup so that the first item is a space or "gray" or something like that. Then just get the value and assign whatever you want.
popupValue = get(handles.popup1, 'Value');
if popupValue == 1 % first item on the list (blank or gray or default or whatever you put in there)
colormap_label = 'gray'
elseif popupValue == 2
colormap_label = 'jet'
elseif popupValue == 3
colormap_label = 'winter'
end
set(handles.colormap_label, 'String', colormap_label);
  2 件のコメント
Meshooo
Meshooo 2014 年 1 月 22 日
Thank you very much but I would like to know what was wrong with my code?
Image Analyst
Image Analyst 2014 年 1 月 23 日
You were trying to access a field of handles that doesn't exist. If you wanted a value or string from a popup, you should have used get() like I did.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Environment Customization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by