App Designer LIST BOX data type
이전 댓글 표시
I am trying to use a LIST BOX in App Designer, to assign one of several different values to a variable. For example, to assign a value to "Density", given a choice of several different metals.
This seemed straightforward but I am getting an error message.....
"Error using matlab.ui.control.internal.model.AbstractNumericComponent/set.Value (line 110) 'Value' must be a double scalar."
What is the default data type of a LIST BOX value, and is there a way to change that value to "Double Scalar"
답변 (1개)
Chris Portal
2018년 5월 14일
편집: Chris Portal
2018년 5월 14일
0 개 추천
The type for the Value property depends on how you've configured the listbox. There are basically 2 scenarios:
- Using Items Property Only: If you only configure the Items property, then the Value property needs to be one of the elements of the Items property. In this case, the type for the Value property is a character vector.
- Using Items and ItemsData Properties: If you configure both the Items and ItemsData properties, then the listbox will continue to visually present what the Items property has, but the Value property is required to be one of the values contained in ItemsData, whatever type that happens to be. (In this case, it's recommended that both Items and ItemsData be the same length. If they're not, the property reference page describes what the resulting behavior is.)
I'm not sure which scenario you're in, but you can find examples for both in the doc:
댓글 수: 5
M G
2018년 5월 16일
M G
2018년 5월 18일
Chris Portal
2018년 5월 20일
Ah, your pictures on the other post helped. It looks to be a bug in the way the editor is converting your entry. I've logged this issue with the team. As a workaround, you can do this (for either listbox or dropdown):
- Clear Out ItemsData: In the property editor for your listbox, delete what you've entered for ItemsData.
- Create a StartupFcn: In Design View, right click on an empty part of the figure region, go to Callbacks, and select Add StartupFcn Callback.
- Configure ItemsData: In Code View, add a line of code to your StartupFcn callback that configures the ItemsData property as you need. Something like:
app.ListBox.ItemsData = [1 2 3 4];
Hope this gets you going!
M G
2018년 5월 20일
카테고리
도움말 센터 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!