I'm writing a MATLAB function to read out data into an n-dimensional array (variable dimension size). I need to be able to access a specific point in the Matrix (to write to it or read it, for example), but I don't know ahead of time how many indexes to specify.
Currently I have a current_point
vector which I iterate through to specify each index, and a max_points
vector which specifies the size of the array. So, if for example I wanted a 3-dimensional array of size 1000-by-15-by-3, max_points = [1000 15 3]
, and current_point
iterates from [1, 1, 1]
to [1000, 15, 3]
([1, 1, 1]
-> [1000, 1, 1]
-> [1, 2, 1]
-> [1000, 2, 1]
->...). What I'd like to be able to do is feed current_point
as an index to the matrix like so:
output_matrix(current_point) = val
But apparently something like output_matrix([1 2 3]) = val
will just set outputmatrix(1:3) = 30
. I can't just use dummy variables because sometimes the matrix will need 3 indexes, other times 4, other times 2, etc, so a vector of variable length is really what I need here. Is there a simple way to use a vector as the points in an index?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…