MATLAB: How to modify the below code such that when clicking on a string from the list box, when clicking on another string it should append to the previously clicked string.

list boxMATLAB

How can I modify the below code such that when clicking on a string from the list box, when clicking on another string it should append to the previously clicked string.
function [] = newnew()
S.fh = figure('position',[400 450 500 200],...
'name','GUI_pop_to_list');
S.pp = uicontrol('style','list',...
'min',0,'max',2,...
'position',[20 90 190 100],...
'string',{'building';'grass';'tree';'cow';'boat';'sheep';'sky';'mountain'});
S.ls = uicontrol();
S.pb = uicontrol('style','push',...
'position',[20 20 190 40],...
'string','Transfer',...
'callback',{@pb_call,S});
uicontrol(S.pp)
function [] = pb_call(varargin)
S = varargin{3};
E = get(S.pp,{'string','value'});
STR = get(S.ls,'string');
set(S.ls,'string',[STR;subplot(1,2,2);imshow('attachment.jpg');title(E{1}(E{2}))])

Best Answer

Instead of this mess:
set(S.ls,'string',[STR;subplot(1,2,2);imshow('attachment.jpg');title(E{1}(E{2}))])
why not make up your string with sprintf(),
myString = sprintf(........);
set(S.ls, 'String', myString);
I have no idea why you're trying to do an imshow() and a call to title() inside a call to send a string to a static text label. That just doesn't make sense at all.