Create contents of popup menu dynamically
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (1)
Jan
am 5 Jul. 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 Kommentare
Carl
am 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
am 18 Aug. 2015
Thanks Jan
Samuel Hirsbrunner
am 23 Jul. 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...
Kategorien
Mehr zu App Building finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!