필터 지우기
필터 지우기

Sum of a Series

조회 수: 2 (최근 30일)
Laura
Laura 2013년 3월 2일
Hi, I am struggling with how to take the sum of the following say i have a vector
A=[1 0 1 0 1 1 0 1 0 1 0]
with L=length(A)
and i want the sum from i=1 to L-1
of the expression
A(i)*(1-(A(i+1)))
i have figured out away to do this with a for loop but is there any way i could do it without?
Thank you in advance for any help.

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 2일
편집: Azzi Abdelmalek 2013년 3월 2일
A=[1 0 1 0 1 1 0 1 0 1 0]
a=A(1:end-1);
b=A(2:end)
out=sum(a.*(1-b))

Wayne King
Wayne King 2013년 3월 2일
A = [1 0 1 0 1 1 0 1 0 1 0];
B = A(2:end);
C = sum(A(1:end-1).*(1-B));

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by