Senyokbalgul
Senyokbalgul

Reputation: 1102

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'))

Upvotes: 0

Views: 185

Answers (1)

Suever
Suever

Reputation: 65430

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'));

Upvotes: 2

Related Questions