Create contents of popup menu dynamically
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (1)
Jan
il 5 Lug 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 Commenti
Carl
il 9 Mag 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
il 18 Ago 2015
Thanks Jan
Samuel Hirsbrunner
il 23 Lug 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...
Categorie
Scopri di più su App Building in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!