Note that there are some explanatory texts on larger screens.

plurals
  1. POMATLAB functions refusing to function depending on placement
    primarykey
    data
    text
    <p>I've written a very simple GUI in <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow noreferrer">MATLAB</a> that will convert temperatures. It is meant to serve as a tutorial for a class of students. A strange thing has happened though. As with any <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" rel="nofollow noreferrer">MVC</a> design pattern, there is a model object, a view object and a controller function. In order to set the output field of the GUI (the converted temperature), you can run this line in the controller function itself:</p> <p><code>set(views.outputTextField,'string',num2str(round(model.outTemp)));</code></p> <p>where <code>views.outputTextField</code> is a GUI text field to display the converted temperature and <code>model.outTemp</code> is the converted temperature. Pretty straightforward. The views object has references to all the GUI uicontrols and this updates the field with the newly converted temperature in the model object.</p> <p>However, I would rather have view functions in the view object, so I attempted to create a line like this:</p> <pre><code>views.updateOutputField = @()set(views.outputTextField,'string',... num2str(round(model.outTemp))); </code></pre> <p>Same line as before, just that now it is an anonymous function in the view object. This way I could call the function from the controllers as simply <code>views.updateOutputField();</code> and keep the view logic out of the controller logic. But this method won't work! (It <em>will</em> work with the <code>get()</code> function.)</p> <p>Instead I have to do the following:</p> <pre><code>views.updateOutputField = @updateOutputField function updateOutputField() set(views.outputTextField,'string',num2str(round(model.outTemp))); end </code></pre> <p>By separating out the function (redundantly) instead of just using an anonymous function, it works again. What!? This makes no sense to me. The view and model objects are global and the anonymous function works with <code>get()</code>. Does anyone have a clue what's going on here?</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.
 

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