Jul 3, 2013 #1 M Mbqmbq Newbie level 5 Joined Jun 11, 2013 Messages 9 Helped 0 Reputation 0 Reaction score 0 Trophy points 1 Activity points 54 Hello all I have a vector in matlab x=(a1 a2 a3 .... a100) and I want to make y=(b1 b2 b3 ... b20) where b1=a1+a2+a3+a4+a5 and b2=a6+a7+a8+a9+a10 and .....b20=a96+a97+a98+a99+a100 please help me ,
Hello all I have a vector in matlab x=(a1 a2 a3 .... a100) and I want to make y=(b1 b2 b3 ... b20) where b1=a1+a2+a3+a4+a5 and b2=a6+a7+a8+a9+a10 and .....b20=a96+a97+a98+a99+a100 please help me ,
Jul 3, 2013 #2 A ahmad1954 Full Member level 4 Joined Jun 30, 2012 Messages 192 Helped 26 Reputation 52 Reaction score 26 Trophy points 1,308 Activity points 2,102 try this m-file code: clear; x=linspace(1,100); y=zeros(1,20); j=1; for i=1:20 for k=j:j+4 y(i)=y(i)+x(k); end j=j+5; end instead of x put your values.
try this m-file code: clear; x=linspace(1,100); y=zeros(1,20); j=1; for i=1:20 for k=j:j+4 y(i)=y(i)+x(k); end j=j+5; end instead of x put your values.
Jul 5, 2013 #3 P Pulkit Varshney Member level 5 Joined Aug 30, 2011 Messages 82 Helped 13 Reputation 26 Reaction score 12 Trophy points 1,288 Activity points 1,731 z=reshape(x,5,20); y=sum(z,1)
Jul 7, 2013 #4 V vickyuet Member level 2 Joined Oct 3, 2006 Messages 50 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,286 Location pakistan Activity points 1,691 If u want indexing based approach for your problem step = 5; y=[sum(x(1,1:step)) sum(x(1,step+1:2*step)) ...... ] or you could use loop also but Pulkit command is concise and elegant.
If u want indexing based approach for your problem step = 5; y=[sum(x(1,1:step)) sum(x(1,step+1:2*step)) ...... ] or you could use loop also but Pulkit command is concise and elegant.