When indexing into a vector with a matrix of variable dimensions, how do I indicate to octave that the index is a matrix and not a vector?
For example, in the following code, on the fourth iteration, Octave sees the index as a row-vector and it transposes the return value of the indexing operation to be a column vector (to match the vector being indexed into rather than the one used for indexing).
When I run:
v = rand(16,1);
t = magic(4);
f = @(m)(sum(m, 1));
for i = 4:-1:1
s = t(1:i,:);
f(v(s))
endfor
I get:
ans =
1.47780 2.28879 1.29786 2.98981
ans =
1.24705 1.31940 0.87484 2.18276
ans =
0.89387 0.55288 0.50312 1.61950
ans = 1.9294
See that on the first three iterations, the answer is a row-vector, but on the last iteration, the answer is a singleton value.
How do I tell octave that the variable s is supposed to be a matrix, not a vector and that the result of the indexing operation should always be the same shape as s?