Sum of all odd and even arrays in matrix

Suppose I have a matrix a:
a = [2,3;1,2;1,2;0,1;1,2;3,1;1,3;2,1;2,3;3,1];
I want to build matrix b with dimension 2*2 that first row is sum up of all odd rows of matrix a and second rwo is sum up of all even rows of matrix a
b = [16;19]

댓글 수: 2

Image Analyst
Image Analyst 2014년 10월 29일
OK, suppose you do. Is this homework? This is very very simple. What have you tried?
the cyclist
the cyclist 2014년 10월 29일
Here is a hint. Do you know how to make a vector of odd numbers? Even numbers?

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

 채택된 답변

Harry
Harry 2014년 10월 29일
편집: Harry 2014년 10월 30일

0 개 추천

From your description, I think you want to do this:
b = [sum(a(1:2:end,:)); sum(a(2:2:end,:))]
However, I'm not sure why you wrote "b = [16;19]". If you want to get that, then just write:
b = sum(a).'

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

Moe
2014년 10월 29일

편집:

2014년 10월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by