Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When I copy-paste your function, I get the following output</p> <pre><code>&gt;&gt; trial(0) 0 0 </code></pre> <p>In my many years using Matlab, I have found a quite a number of strange behaviours and Matlab bugs, but I have never seen Matlab change a variable just like that. Thus, my suspicion is that there really is a bug in your code.</p> <p>In order to find the problem, I suggest that you set a stop in every line where <code>test</code> appears, so that you can check its value as you go through the function. Alternatively, you can periodically set conditional stops (set a stop normally, then right-click to enter a condition, such as <code>test==1</code>) so that the function halts execution when <code>test</code> has taken on an undesired value. This should allow you to quickly identify the place where bad stuff happens.</p> <p>Once you identify the problematic code block, you can create a (relatively) small test case and post it here, in case the error has not become obvious.</p> <p><strong>EDIT</strong></p> <p><a href="https://stackoverflow.com/questions/2718308/matlab-is-changing-variables-when-i-do-not-want-it-to/2720045#2720045">@woodchips</a> has suggested several possible causes for your bug. My money would be on the precision problem, i.e. that you compare <code>0.000000001</code> to <code>0</code>. To find such a problem, put a debug stop on every if-statement that involves <code>test</code> and check whether <code>round(test)==test</code>. If the output is <code>false</code>, you just replace <code>test</code> with <code>round(test)</code> in your if-statement, and you're done.</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.
    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