Create contents of popup menu dynamically
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
Jan
el 5 de Jul. de 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 comentarios
Carl
el 9 de Mayo de 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
el 18 de Ag. de 2015
Thanks Jan
Samuel Hirsbrunner
el 23 de Jul. de 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...
Categorías
Más información sobre App Building en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!