Your sample output is not legal. A matrix cannot have rows of different length. What you can do is create a cell array using arrayfun
:
values = arrayfun(@colon, idx1, idx2, 'Uniform', false)
To convert the resulting cell array into a vector, you can use cell2mat
:
values = cell2mat(values);
Alternatively, if all vectors in the resulting cell array have the same length, you can construct an output matrix as follows:
values = vertcat(values{:});