Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using the function <a href="https://www.mathworks.com/help/matlab/ref/sub2ind.html" rel="nofollow noreferrer"><code>sub2ind</code></a> to create a <a href="http://www.mathworks.com/help/matlab/math/matrix-indexing.html#f1-85511" rel="nofollow noreferrer">linear index</a> is the typical solution to this problem, as shown in this <a href="https://stackoverflow.com/q/792683/52738">closely-related question</a>. You could also <a href="https://stackoverflow.com/q/1146719/52738">compute a linear index yourself</a> instead of calling <code>sub2ind</code>.</p> <p>However, your case may be simpler than those in the other questions I linked to. If you're only ever indexing a <em>single</em> point with your <code>current_point</code> vector (i.e. it's just an n-element vector of subscripts into your n-dimensional matrix), then you can use a simple solution where you convert <code>current_point</code> to a cell array of subscripts using the function <a href="https://www.mathworks.com/help/matlab/ref/num2cell.html" rel="nofollow noreferrer"><code>num2cell</code></a> and use it to create a <a href="https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html" rel="nofollow noreferrer">comma-separated list</a> of indices. For example:</p> <pre><code>current_point = [1 2 3 ...]; % A 1-by-n array of subscripts subCell = num2cell(current_point); % A 1-by-n cell array of subscripts output_matrix(subCell{:}) = val; % Update the matrix point </code></pre> <p>The operation <code>subCell{:}</code> creates the equivalent of typing <code>subCell{1}, subCell{2}, ...</code>, which is the equivalent of typing <code>current_point(1), current_point(2), ...</code>.</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. 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