Create contents of popup menu dynamically
Afficher commentaires plus anciens
I want to create a popup menu with contents dynamically,based on value of a variable n in my code.
Example:- If n is 2,the contents should be Data1,Data2.
If n is 3,the contents should be Data1,Data2,Data3.
...................................................
If n is x,the contents should be Data1,Data2,......Datax
Réponse acceptée
Plus de réponses (1)
Jan
le 5 Juil 2012
String = sprintf('Data%d#', 1:n);
String(end) = [];
CString = regexp(String, '#', 'split');
uicontrol('Style', 'popupmenu', ...
'String', String, ...
'Units', 'pixels', ...
'Position', [370, 60, 95, 21]);
3 commentaires
Carl
le 9 Mai 2013
Actually, the code can be simplified even further from Jan's answer. For a popup menu with multiple lines, you break the lines by the '|' character when feeding in a string to the 'uicontrol'. So just use this line of code:
String = sprintf('Data%d|',1:size(Data))
But Jan's answer is very elegant.
Mus'ab Ahmad
le 18 Août 2015
Thanks Jan
Samuel Hirsbrunner
le 23 Juil 2016
finde this on my researches... I may shorten the code again:
String = sprintf('Data%d\n',1:size(Data))
by adding "\n" it made a new line on each value. so no need for the regesp() at least i think this works...
Catégories
En savoir plus sur App Building dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!