MATLAB GUI pop-up menu list get disappear when I set a default string? - matlab

can somebody please tell me why my pop-up menu list get disappear when I set a string which actually belongs to one of the item in the list? I want this string to be appear as default when GUI gets open, however, want other items to be in the pop-up menu.
For example, pop-up list contains:
Set_1
Set_2
Set_3
Set_4 etc..
And, in the function OpeningFcn, I am settting:
set(handles.popupmenu1, 'String', 'Set_1');
This makes 'Set_1' to appear when I open GUI. However, it makes other items (Set_2, Set_3 etc) disappear from the GUI. Thanks.

The String property of a popupmenu uicontrol sets the entire text that is displayed in the menu.
To select a particular option, set the Value property to the index of the item to be selected. In this case, since Set_1 is the first item, set the Value property to 1.

Related

How to get `length` of Matlab GUI popup menu strings

I want to get how many strings exist in the popup menu, how can this be done? This code that I have written does not seem to work.
length(get(handles.popupMenu,'Value'))
Value is the index of the currently selected item in the menu so it will only ever be a scalar. You instead want to check the length of the String property which contains a cell array of strings (one for each item).
nOptions = numel(get(handles.popupMenu, 'String'));

Infopath: Rules with Multiple Selection List Box do not trigger

Im trying to implement several rules for a form, based on a selection of some multiple selection list boxes. Im customizing a form for a existing SharePoint list by clicking on "Customize Form" in SharePoint. First of all, the choice fields on the list (multiple selection) are oddly binded in InfoPath:
I cant change the variable's name "Value" and Real Estate Categories should not be a required field. (*)
On one view I have a "Business Unit Purchase" box that is a multiple selection box (choice) and there is a next button. The next button should only be availiable when a selection is made.
So I tried to the following rules for the Next Button:
Rule Type Action:
IF Value (of Business Unit Pruchase) is not blank -> Switch to next view
This works properly, but now i wanted to disable the next button when nothing is the text box was selected, because it makes it more clear to have a selection beofre ist possible to go on. So I tried this:
Rule Type Formatting:
IF Value is blank -> disable this control
This disables the button as wanted when the multiple text box has not any items selected, but after selecting one or more, nothing happens. Is there any reason why this does not work?
Normally when a selection is made, the field "value" of "Business Unit Purchase" should contain one or more strings and therefor should not be blank anymore.
A multiselect list box almost always contains one blank element entry unless it has been manually removed (e.g. via code).
Because of this, the condition Value is blank will almost always be true.
To remedy this, use the dropdown in the Condition builder's field selection dialog to set up your condition as:
All occurrences of Value are blank -> Disable this control
If you do this, the control should be enabled when one or more items are selected.

How to write a callback for popup menu in matlab?

I have four items(Types of soils) to be inserted in popup menu and the output should be integer values(porosities) displayed using a static text. How this can be done?
I guess you will be using GUIDE to create your GUI. Here is a simple code for populating a popup menu with pre-defined strings and use the selected item to change the displayed output in the static text:
1) In order to populate the popup menu, simply create a cell array of strings and set the 'String' property of the menu to that cell array:
% Create cell array
SoilTypes = {'Soil A' 'Soil B' 'Soil C' 'Soil D'};
% Set the string property of the popup menu:
set(handles.popupenu1,'String',SoilTypes);
2) Now the callback you are talking about seems to be the Selection Change callback, which might look like this:
function Popupmenu1_SelectionChangeFcn(hObject, eventdata, handles)
This gets executed when the user changes the selected item in the popupmenu. Therefore, you want to get the selected item with this line:
get(handles.popupmenu1,'Value')
So according the the previous cell array, you can use (among other options) a switch/case scenario in which you can do whatever stuff you want for every type of soil, such as displaying text in the static text box. You can also set directly the string in the text box like so:
SelectedItem = get(handles.popupmenu1,'Value') % Get the value, from 1 to 4 in your case
set(handles.text1,'String',SoilTypes{SelectedItem}); % Display the corresponding soil type
Hope that helps get you started!

save data to popupmenu

I have a popup-menu that has an option, add own material, and when this is chosen, a pushbutton is enabled that say SAVE. I alose have a bunch of edit-boxes.
What I want to do is to make a callback so whenever I click the SAVE, the data from one of the textboxes will possible to select in the popupmenu. when this is selected, I want to set the other edit-boxes to contain the same data that they did when I clicked the save button.
Thanks in advance
I'm not quite sure to fully understand what you want, but you can use the handle of the popup menu to get the string/string array in contains at the time you press the pushbutton. Then you can put those inside the textboxes using their handles as well.
For instance:
MyStrings = get(handlesToYourPopupMenu,'String');
or
MyStringsArray = cellstr(get(handlesToYourPopupMenu,'String'));
which contains the content of the popup menu as a cell array.
and
set(handlesToYourEditBox,'String',MyString);
Is that what you mean? If not please ask :)
EDIT:
To add the new data to the existing content of your text box, use concatenation. Since the content is in a cell array, you can do the following:
NewString = [OldString {CurrentString}];
where CurrentString is obtained with
get(hanlesToYourEditBox,'String');
Therefore to update the content of the popup menu you could write this:
set(handlesToPopUpMenu,'String',[MyStringsArray {get(hanlesToYourEditBox,'String')}]):

GWT: How to know if my listbox selected index changed

I have a listbox ,which have two values value1 and value 2 ..
Now my listbox values got change programatically (I dont change the values Manually)
I want to get a prompt prompt whenever a value get changes / index get changed, inside my listbox
ListBox listBox = new LisBox();
if i use
listBox.addClickHandler
or
listBox.addChangeListener
or
listBox.addChangeEvent
They all only shows me a prompt when i manually change my listbox selected Index.But how will i get a prompt when my listbox selectedIndex changed programatically
Thanks
I am assuming that you are using
setSelectedIndex
The javadoc says explicitly states that it will not send an event. You could overwrite setSelectedIndex and send your own event. A good explaination of doing so can be found here.