Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to check a matrix is/isn't in an array (Matlab)
    primarykey
    data
    text
    <p>I have an array (M) of matrices. I perform an operation on the matrix in the ith position, and it adds three more matrices to my array in the (3i-1), (3i) and (3i+1)th positions. I want to continue this process until I reach the jth position in the array, where j is such that all matrices in the (j+1)th position and onwards have appeared already somewhere between positions 1 and j (inclusive).</p> <p>EDIT: I've been asked to clarify what I mean. I am unable to write code that makes my algorithm terminate when I want it to as explained above. If I knew a proper way of searching through an array of matrices to check if a given matrix is contained, then I could do it. I tried the following:</p> <pre><code>done = 0; ii = 1 while done ~= 1 %operation on matrix in ith position omitted, but this is where it goes for jj = ii+1:numel(M) for kk = 1:ii if M{jj} == M{kk}; done = done + 1/(numel(M) - ii); break end end end if done ~= 1 done = 0; end ii = ii + 1 end </code></pre> <p>The problem I have with this (as I'm sure you can see) is that if the process goes on for too long, rounding errors stop ever allowing done = 1, and the algorithm doesn't terminate. I tried getting round this by introducing thresholds, something like</p> <pre><code>while abs(done - 1) &gt; thresh </code></pre> <p>and </p> <pre><code>if abs(done - 1) &gt; thresh done = 0; end </code></pre> <p>This makes the algorithm work more often, but I don't have a 'one size fits all' threshold that I could use (the process could continue for arbitrarily many steps), so it still ends up breaking.</p> <p>What can I do to fix this?</p> <p>Thanks</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