필터 지우기
필터 지우기

Question about summations from excel (backwards sum)

조회 수: 1 (최근 30일)
Omar
Omar 2014년 2월 3일
답변: Azzi Abdelmalek 2014년 2월 3일
Hello, I have an imported excel file. Say I have 2, 1x20 Matrix (set as A and B respectively). How can I make an upside down sum between my matrices? Instead of going from i=0 to i=20 , I want to go from i=20 to i=0. An easy fix could be re-arranging the excel files but I wanna know if theres a way around with matlab.

답변 (3개)

Roger Stafford
Roger Stafford 2014년 2월 3일
편집: Roger Stafford 2014년 2월 3일
s = sum(fliplr(A)+fliplr(B));
Note: Whatever order 'sum' would have taken with A+B will be reversed.

Wayne King
Wayne King 2014년 2월 3일
편집: Wayne King 2014년 2월 3일
There are a couple issues here. A sum that goes from 0 to 20 has 21 elements not 20 as you indicate. Further, summation is commutative so why does it matter what order you sum in?
A = randn(2,20);
sum(A,2)
B = fliplr(A); % reverse the elements in the rows of A
sum(B,2)
What have I misunderstood?
fliplr() reverse the rows of A (reverses each row of A)
  댓글 수: 1
Omar
Omar 2014년 2월 3일
Small mistake on my part for the 20 terms. Im aware that its commutative but my true task is to find the summation of the average of the lowest 2 terms of my matrix * the sum of the upper 2 terms of my other matrix and so on.
F=fliplr(A);
S=sum(((F(1:20)+F(2:20))/2).*(B(1:20)+B(2:20)))
Will this do?

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


Azzi Abdelmalek
Azzi Abdelmalek 2014년 2월 3일
Your question is not clear, maybe you want
A=[ 1 2 3 4]
B=[10 20 30 40]
out=cumsum(fliplr(A+B))

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by