function - How to create more than one matrix in a row using matlab -


i trying series of vectors come same original, make easy example, suppose vector v= (1,2,3,4,5,6,7,8,9,10) (of course mine bigger)

the first vector has this:

r1=(1,3,5,7,9)= v(1:1:end)  second vector: r2=(2,4,6,8,10)=v(2:1:end) third vector: r3=(3,5,7,9)=v(3:1:end) fourth vector: r4=(4,6,8,10)=v(4:1:end) ... r8=(8,10)=v(8:1:end) 

so questions are:

  1. is there easier way result?
  2. how can know total number of ri vectors distance = 1 can obtained v?

use matlab's cell object can hold vector in every cell. use loop fill cell object gradually.

code example:

%initialize v v= [1,2,3,4,5,6,7,8,9,10];  %initialize empty cell of size [10,1] r= cell(length(v)-2,1);   %fill cell ii=1:length(r)    r{ii} = v(ii:2:end);  end  %prints results ii=1:length(r)    r{ii}  end 

results (each row different vector):

 1     3     5     7     9  2     4     6     8    10  3     5     7     9  4     6     8    10  5     7     9  6     8    10  7     9  8    10 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -