Re: MATLAB help
Hi Jw3Crystal,
There's lot of ways to do what you want. You may find it easier, rather than creating different vectors, to create matrices (which are really just vectors of vectors).
A simple way to complete the problem you have above is to use the command CIRCSHIFT. You can use help circshift to get the exact info on what this does. But in short, it just rotates positions by an arbitrary number of positions. So you could do:
PHP Code:
baseVec=[1; 0; 0; 0; 0; 0; 0; 0; 0; 0]
vec1=circshift(baseVec,1)
The output should be:
[0; 1; 0; 0; 0; 0; 0; 0; 0; 0]
A more elegant method, using matrices could be something like:
PHP Code:
lonelyOneMat=zeros(10,10) %creates a 10x10 matrix in memory
lonelyOneMat(1,1)=1 %sets the top left element to 1
for i=2:size(lonelyOneMat,2) %do this loop for every column
lonelyOneMat(:,i)=circshift(lonelyOneMat(:,1),i-1); %shift each column vector by i-1 locations
end
To adapt this for other original baseVectors you can just assign more values to 1 inititialy:
lonelyOneMat(:,1)=[0;1;0;1;0;0;0;0;0;0]
!!!! NOTE this won't give you all posibilities for the locations of the two ones, to do that, you really need to create 45 different vectors (10 chose 2). !!!!
Some things you should learn and experiment with:
The colon operator (

does many things in different contexts. In the context above, it selects all the elements in the given dimension of a matrix. You can read up on in in the matlab help
You never ever want to do "grow" vectors in a matlab for loop. By growing I mean keep making the vector longer. This operation takes a looong time and will really slow down your loops. Assign the memory beforehand (just like you would in C or C++) and you can see orders of magnitude speedups in processing.