addition , subtraction

조회 수: 1 (최근 30일)
nand mourya
nand mourya 2011년 5월 19일
[EDIT: 20110519 14:45 CDT - reformat - WDR]
Hi, I need help in coding the following example.. thanks
S is (mXn) matrix and d is (mX1) array
S(1,:) = [0 0.2 0.3 0.5 0.6 0.7 0.72 0.75 ...... 1 ]
for example length(S(1,:)) = odd (lets say 7)
d(1)= S(1,1) + (S(1,3)-S(1,2))+(S(1,5)-S(1,4))+(S(1,7)-S(1,6))
...and so on...
if length(S(1,:)) = even(lets say 8)
d(1)=S(1,1) + (S(1,3)-S(1,2))+(S(1,5)-S(1,4))+(S(1,7)-S(1,6))
i.e. neglect S(1,8)
I want to run this program in a loop for entire S matrix and find the array d

채택된 답변

Walter Roberson
Walter Roberson 2011년 5월 19일
d = Sum(S(:,1:2:end),2) - Sum(S(:,2:2:end-1),2)
  댓글 수: 2
Andy
Andy 2011년 5월 19일
Ninja'd! Walter, you need lower case sums.
Walter Roberson
Walter Roberson 2011년 5월 19일
Good point, Andy. I've been flipping between programming languages too much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by