Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When you <code>set</code> a property of a handle like <code>set(h,'String',str)</code>, the value of <code>str</code> is copied. It is not a reference to that variable that can be updated automatically. Your best bet is to make a subroutine called <code>updateText</code> or something like that, put all of the <code>set</code> statements in it, and call it when needed.</p> <p>Calling <code>guidata(hObject, handles);</code> is only for <em>updating</em> the GUI with modifications to <code>handles</code>. You may need this elsewhere, but for the job of updating properties of certain handle graphics objects, it is not really used.</p> <hr> <p>One possibility is to create a <a href="http://www.mathworks.com/help/matlab/ref/timerclass.html" rel="nofollow"><code>timer</code></a> to update the text fields on a regular basis. In your GUI's opening function, create a timer that defines an update function to run periodically:</p> <pre><code>T = timer('Period',1,'StartDelay',0.5,'TimerFcn', ... {@updateTextBoxes,handles},'ExecutionMode','FixedRate'); start(T) </code></pre> <p>The update function would look like:</p> <pre><code>function updateTextBoxes(hTimerObj, timerEvent, handles) global mystruct % get mystruct data however you do it... % maybe also get handles via handles=guidata(hTimerObj); instead of input set( handles.textfield1, 'String', mystruct.value1 ) ... set( handles.textfieldN, 'String', mystruct.valueN ) </code></pre> <p><strong>EDIT</strong>: Do NOT forget to delete the timer (<code>delete(T)</code>) or stop it before you quit the GUI or do <code>clear T</code>, otherwise it will just keep running and you will have to quit MATLAB... No, I did not just do this myself!</p>
 

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