Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, you will have to make sure you suppress any output to the command window. You can do this by making sure you end lines with a <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f0-41244.html#f0-45379" rel="nofollow noreferrer">semicolon</a>, avoid using the <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/disp.html" rel="nofollow noreferrer">DISP</a> function to display data, and avoid using the <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fprintf.html" rel="nofollow noreferrer">FPRINTF</a> function to send data to the standard output (i.e. command window).</p> <p>Second, determine what sort of "results" you are wanting to display. If it is a vector or matrix of numeric values, you may want to use a <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/uitable.html" rel="nofollow noreferrer">UITABLE</a> object instead of a static text box (as suggested in <a href="https://stackoverflow.com/questions/957215/how-can-i-use-a-listbox-in-matlab/957944#957944">Azim's answer to your other question</a>, and assuming you have one of the newer versions of MATLAB). If it is just a couple of numeric values, characters, or strings, then I would suggest using a static text box. For example:</p> <pre><code>hList = uicontrol('Style','text','Position',[100 100 200 200]); set(hList,'String',{'Line 1'; 'Line 2'}); % Displays 2 lines, one string each vec = rand(3,1); % Column array of 3 random values set(hList,'String',num2str(vec)); % Displays 3 lines, one number per line </code></pre> <p>With this option, you will probably end up doing a lot with <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/strings.html" rel="nofollow noreferrer">string operations</a>.</p> <p><strong>NOTE:</strong> With static text boxes, if you put more text in them than they are able to display, they will simply cut off the text. They do not automatically create sliders to view the whole piece of text. You will either have to make the static text box bigger, adjust the <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/uicontrol_props.html#bqxoilz" rel="nofollow noreferrer">"FontSize" property</a> of the static text box to a smaller value, or (the more complicated option) create your own slider which will adjust what is displayed in the text box.</p> <hr> <p><strong>EDIT: The more complicated option...</strong></p> <p>In case anyone is interested, I thought I'd include some sample code for making a static text box with a slider that controls the contents displayed in the text box. There are quite a few different ways to do this, ranging from the simplest implementation I can think of (given below) to more complicated versions using <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f4-39683.html" rel="nofollow noreferrer">nested functions</a> and <a href="http://www.mathworks.com/products/matlab/object_oriented_programming.html" rel="nofollow noreferrer">fancy OOP stuff</a>.</p> <p>First, you will have to have the two following functions saved as m-files:</p> <p><em>callback_scrolltext.m</em></p> <pre><code>function callback_scrolltext(source,event,hText) textString = get(hText,'UserData'); nLines = numel(textString); lineIndex = nLines-round(get(source,'Value')); set(hText,'String',textString(lineIndex:nLines)); end </code></pre> <p><em>update_scrolltext.m</em></p> <pre><code>function update_scrolltext(newText,hText,hSlider) newText = textwrap(hText,newText); set(hText,'String',newText,'UserData',newText); nRows = numel(newText); if (nRows &lt; 2), sliderEnable = 'off'; else sliderEnable = 'on'; end nRows = max(nRows-1,1); set(hSlider,'Enable',sliderEnable,'Max',nRows,... 'SliderStep',[1 3]./nRows,'Value',nRows); end </code></pre> <p>Second, create the GUI objects with the following code. You can set the 'Position' properties to whatever you want, as well as use any handle for a figure or panel object in place of <strong>hParent</strong>: </p> <pre><code>hParent = figure; hText = uicontrol('Style','text',... 'Parent',hParent,... 'Units','pixels',... 'Position',[100 100 100 40]); hSlider = uicontrol('Style','slider',... 'Parent',hParent,... 'Units','pixels',... 'Position',[200 100 10 40],... 'Enable','off',... 'Callback',{@callback_scrolltext,hText}); </code></pre> <p>Finally, every time you want to change the text of the text box, call <strong>update_scrolltext</strong> with the text you want to display (contained in a cell array just like the string input to <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/textwrap.html" rel="nofollow noreferrer">TEXTWRAP</a> is) and the handles of the text box and slider. Here are some examples to try:</p> <pre><code>update_scrolltext({'hello'},hText,hSlider); update_scrolltext({'hello'; 'there'; 'silly'; 'world'},hText,hSlider); </code></pre> <p>Modify the code as you see fit and enjoy! =)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload