user interface - Insert a new line in listbox on Matlab GUIDE -


i'm building gui using guide , have listbox want receive several messages after click in send_button every time click on button message shows in first line.

function send_button_callback(hobject, eventdata, handles) % hobject    handle send_button (see gcbo) % eventdata  reserved - defined in future version of matlab % handles    structure handles , user data (see guidata)      % text   dstid = get(handles.dest_id,'string');   msg = get(handles.message_box,'string');    % message_box = editbox    % build message , send   msg = {['< ', dstid, ' >     ', msg]};      % dstid = number   set(handles.message_list, 'string', msg);   % message_list = listbox 

what should in order have like

<3> message 1 <3> message 2 <3> message 3 

i think happens because msg string don't know how insert '\n' or that.

you can cell array of strings containing items of listbox get(handles.message_list,'string'). here's way solve problem.

function send_button_callback(hobject, eventdata, handles) % hobject    handle send_button (see gcbo) % eventdata  reserved - defined in future version of matlab % handles    structure handles , user data (see guidata)    % text dstid = get(handles.dest_id,'string'); msg = get(handles.message_box,'string');    % message_box = editbox  %get lisbox cell array of strings cell_listbox = get(handles.message_list,'string'); %length needed in order append desired message @ end length_cell_listbox = length(cell_listbox);  % build message , send msg = ['< ', dstid, ' >     ', msg];      % dstid = number cell_listbox{length_cell_listbox + 1} = msg; set(handles.message_list, 'string', cell_listbox);   % message_list = listbox 

using same idea can create button deletes last message stored in listbox.


Comments

Popular posts from this blog

Issues changing the value of an element in an array in matlab -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

vb.net - Alternative to the T-SQL AS keyword -