Method to compound daily data by n-days?
    10 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
Given:
[1 2 3 4 5 6] and n = 1,
return [1, 2, 3, 4, 5, 6]
given n=2, return: [1*2, 3*4, 5*6]
given n=3, return: [1*2*3, 4*5*6]
given n=4, return [1*2*3*4]
given n=5, return [1*2*3*4*5]
given n=6, return [1*2*3*4*5*6]
not sure what to call this algorithm, but can anyone think of a clever way to do it?
0 Kommentare
Antworten (2)
  Yi Sui
 am 12 Sep. 2012
        function re = foo(x,n)
len = length(x);
seg = floor(len/n);
res = mod(len,n);
x2 = mat2cell(x,1,[ones(1,seg).*n res]);
re = cellfun(@prod,x2);
re = re(1:end-1);
0 Kommentare
  Andrei Bobrov
      
      
 am 12 Sep. 2012
        I = 1:6; % The initial array
out = nonzeros(prod(reshape([I,zeros(1,mod(-numel(I),n))],n,[])))';
0 Kommentare
Siehe auch
Kategorien
				Mehr zu Logical finden Sie in Help Center und File Exchange
			
	Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


