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:
- is there easier way result?
- how can know total number of ri vectors
distance = 1
can obtainedv
?
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
Post a Comment