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 个评论

BTW: I have found this reply to a similar question.....
https://stackoverflow.com/questions/45122921/numerical-values-associated-with-drop-down-options/45126393#45126393
However, this "answer" applies to UIFigures created programmatically, not within the App Designer framework. It may, however, offer a hint to somebody out there who is more familiar with both App Designer and programmatic UIFigures

请先登录,再进行评论。

回答(1 个)

Chris Portal
Chris Portal 2018-5-14
编辑:Chris Portal 2018-5-14
The type for the Value property depends on how you've configured the listbox. There are basically 2 scenarios:
  1. 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.
  2. 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
M G 2018-5-14
编辑:M G 2018-5-14
Thank you once again for the reply. I can see that these changes are possible if you are creating the UIFigure in a programmatic way. But in App Designer, there seems to be no way to implement these sorts of changes, except via the ListBoxProperties dialog panel. And there, I don't see any choices to alter the Data Type.
So, when viewing this in App Designer, I do not see how to make any changes to the Item properties. I interpret the error message as indicating that the LIST values are considered to be text, not numerical, or are Single-precision numerical instead of Double precision.
As a newbie, it's entirely possible that I am blind to what I should be seeing... Some gentle guidance would be appreciated.
Update: I have tried using a Drop Down field instead of List Boxes and I am getting the same / similar error messages. This would seem to be straightforward----pick an "item" which has a value associated with it and then use that value in a (hidden) calculation. So, why the difficulty? Error messages include "not a double scalar", "matrix dimensions are not the same" and so forth. Even when I reduce the lists to only one item each, I am still getting errors. Obviously, I am missing something which might be blindingly obvious but, still, I am missing it. Any hints? _ Some gentle guidance would be appreciated._
I posted another Question about this problem, with some screen shots and related comments, in the hope that this will help. Please check out that question at https://www.mathworks.com/matlabcentral/answers/400960-how-to-set-app-designer-drop-down-and-list-box-data-types?s_tid=prof_contriblnk
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):
  1. Clear Out ItemsData: In the property editor for your listbox, delete what you've entered for ItemsData.
  2. Create a StartupFcn: In Design View, right click on an empty part of the figure region, go to Callbacks, and select Add StartupFcn Callback.
  3. 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!
Chris: Thanks for your Answer.
First of all, it is great to know that this is a systemic (bug) problem and not the result of a misunderstanding or insanity on my part!
I had the concept that, if only one could define the data type elsewhere (at start-up)the App would run, but it didn't make sense to me that a fundamental bug like this would still be in App Designer (not a newly introduced package...) and that I'd be the first one to find it. So I spent a lot of energy re-tracing every bit of documentation I could find.
I've not tested your stop-gap solution yet, as I've run to the end of my MatLab trial period and have yet to purchase a License. But as soon as that is in place I will give it a go!

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

提问:

M G
2018-5-13

评论:

M G
2018-5-20

Community Treasure Hunt

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

Start Hunting!

Translated by