vector or matrix in matlab

Status
Not open for further replies.

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 ,
 

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.
 

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.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…