Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One method to produce every feasible integer vector within a specified range using Matlab is to use the meshgrid function. Here's an example:

Suppose you want to create all possible integer vectors between 1 and 3 for each of 4 elements. You can use the following code:

range = 1:3; % range of values
n = 4; % number of elements in the vector
[X1,X2,X3,X4] = ndgrid(range); % create all possible combinations
vectors = [X1(:), X2(:), X3(:), X4(:)]; % combine into a matrix of vectors

The ndgrid function creates a grid of all possible combinations of the range of values, and the resulting matrices X1, X2, X3, X4 represent the values along each dimension. The colon operator (:), when used with the parentheses, reshapes the resulting matrices into column vectors, which are then concatenated into a matrix of all possible vectors.

The resulting matrix "vectors" will have 3^4 = 81 rows (since there are 3 possible values in the range, and 4 elements in the vector), with each row representing a unique vector. You can change the "range" and "n" parameters to generate vectors with different ranges and lengths.