Sum of all odd and even arrays in matrix

10 vues (au cours des 30 derniers jours)
Moe
Moe le 29 Oct 2014
Modifié(e) : Harry le 30 Oct 2014
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 commentaires
Image Analyst
Image Analyst le 29 Oct 2014
OK, suppose you do. Is this homework? This is very very simple. What have you tried?
the cyclist
the cyclist le 29 Oct 2014
Here is a hint. Do you know how to make a vector of odd numbers? Even numbers?

Connectez-vous pour commenter.

Réponse acceptée

Harry
Harry le 29 Oct 2014
Modifié(e) : Harry le 30 Oct 2014
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).'

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by