The following problem leaves me head scratching:
I am indexing a vector R with dimensions Nx1 with a matrix, ie:
R = ones( [ N nSteps ] );
R = (:);
with a matrix of indicies. Basically each row of the matrix is a row of indicies for which I need the values stored in R, this is to have vectors out of R with different offsets off a current point in R. The matrix would look like the result of:
k = 0:nSteps;
I = repmat( k , [size(D,2) 1])
I = bsxfun(@minus, I , D');
% later in code, this is used as:
currI = currPoint + currI;
% this is used for indexing just a little later
... R(currI) ...
D in this example is an array storing the different offsets I want. It works perfectly in most cases and gives me arrays of dimensions [size(D,2) nSteps] as a result of the indexing with I can use.
Here is where the problem starts: The amount of offsets is passed as a parameter to the function and can vary. Whenever I try to use just one simple offset, for example 400, I run into problems. Matlab doesn't seem to care if something gets indexed by a 1xN or Nx1 vector and always returns, in this case, a vector with dimensions [nSteps 1] instead of [1 nSteps]. As the result is then used in a call for bsxfun, the result of that function no longer is a matrix of [size(D,2) nSteps] but a [nSteps nSteps] matrix with which I can do nothing and is also ill-defined in the context of the algorithm.
TLDR: Can I make matlab give me a 1 x N array when indexing R(1:400) instead of a N x 1 array? Can I force consistency with indexing with matrices?