Note that there are some explanatory texts on larger screens.

plurals
  1. PODetect non-uniform direction in a Matrix
    primarykey
    data
    text
    <p><strong>Background</strong></p> <p>Given a matrix like this:</p> <pre><code>X = [1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8] </code></pre> <p>We can see that each number is increasing both to the right and down. However the direction doesn't matter, as long as the direction/slope is uniform.</p> <p>This can be tested by:</p> <pre><code>&gt; gradient(X) &gt;= 0; ans = [1 1 1 1 1; 1 1 1 1 1; 1 1 1 1 1; 1 1 1 1 1] </code></pre> <p>and</p> <pre><code>&gt; gradient(X') &gt;= 0 % transpose of X ans = [1 1 1 1 1; 1 1 1 1 1; 1 1 1 1 1; 1 1 1 1 1] </code></pre> <p>In this example I am assuming that the data is increasing right/down, it would not be a complicated task to extend to any uniform direction.</p> <p>This can be combined into the full test:</p> <pre><code>&gt; all(all(gradient(X) &gt; 0)) &amp;&amp; all(all(gradient(X') &gt; 0)) ans = 1 </code></pre> <p><strong>Question:</strong></p> <p>How can I detect any deviation from this uniform direction and "fix" it. The fix should involve interpolating a value from the surrounding points.</p> <p><strong>Note:</strong></p> <p>In practice these matrices are quite large and contain values which might only differ by tiny amounts. I am assuming at the moment that there will only be one deviation at a time, they won't be grouped together: <code>[1 2 3 2 4 5] (2 is an error)</code> for example, rather than <code>[1 2 3 2 1 4] ([2 1] is an error)</code></p> <p><strong>Edit:</strong></p> <p><code>[1 2 3 2 4 5]</code> should become <code>[1 2 3 3.5 4 5]</code> Where 3.5 is the interpolated value of the surrounding points (in this case the average of 3 and 4).</p> <p><strong>Edit2:</strong></p> <p>Ignore the interpolation part, I will work that out later.</p> <p>Given </p> <pre><code> X = 1 2 3 4 5 2 3 2 5 6 3 4 5 6 7 4 5 6 7 8 </code></pre> <p>2 is obviously the "error". I would like the following as output:</p> <pre><code>2 3 4 3 2 5 4 5 6 </code></pre> <p>Which is the error value and the surrounding points. From these points I will do a 2D interpolation to replace 2 with (hopefully) 4, using 3, 3, 5, and 5 (ignoring the corners 2, 4, 4, and 6).</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.
 

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