Hello, thanks for reading this,
What I want to do is set up a listbox that outputs a work log of what I do in the GUI. What I do is output strings to the listbox whenever I do a certain task. My problem is whenever I output a string, it overrides what was already there.
What I do is set the handle for the listbox to a string value whenever I output a new string using set(handles.listbox, ...), and I know this is the problem because I'm continually setting the listbox to a new value. My issue is I don't know how to dynamically add to it without deleting what was already there, it seems wasteful to continually delete and populate it.
What I was thinking of doing is adding to a continually existing string, or concatenate several strings into a longer one using cells. I would still be continuously deleting and populating it, but I wouldn't know how else to do it. Is this the best way, or is there something better to do I'm not understanding?

 採用された回答

per isakson
per isakson 2014 年 5 月 14 日
編集済み: per isakson 2014 年 5 月 14 日

0 投票

"it overrides what was already there" that's the way Matlab works. You need to
  • get what's in the listbox
  • add the new entry to the list
  • set the entire list
Example:
figure
lbh = uicontrol( 'Style', 'Listbox', 'String', {'line1','line2'} );
str = get( lbh, 'String' );
str = cat( 1, {'new line'}, str );
set( lbh, 'String', str )
str{end+1} = 'bottom line';
set( lbh, 'String', str )

3 件のコメント

Brian
Brian 2014 年 5 月 14 日
編集済み: Brian 2014 年 5 月 14 日
This is a bit embarrassing to say, but this seems like it would work exactly as I need it to.
Such a simple solution to what I imagined would be a hassle.
One last question: I'm having problems with adding newlines to the string. Whats the best way to handle this?
Thanks again for your help.
per isakson
per isakson 2014 年 5 月 14 日
編集済み: per isakson 2014 年 5 月 14 日
I find it most convenient to use a cell array of strings as in the example I added to my answer.
Brian
Brian 2014 年 5 月 14 日
Thanks, I got it to work!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Desktop についてさらに検索

質問済み:

2014 年 5 月 14 日

編集済み:

2014 年 5 月 14 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by