필터 지우기
필터 지우기

Sum of matrix elements

조회 수: 4 (최근 30일)
Royvg94
Royvg94 2015년 9월 29일
편집: Royvg94 2015년 9월 30일
Lets use this as an example:
I have a matrix A of 5 x 5, and i want a new matrix B of 5 x 1, with the sum of column 2 and 4, of each seperate row.
For example
A = [15, 47, 56, 36, 58; 92, 41, 23, 19, 3; 9, 78, 66, 21, 30; 2, 14, 10, 96, 91; 12, 22, 77, 70, 1]
Then i want B to be B = [47+36; 41+19; 78+21; 14+96; 22+70] B = [83; 60; 99; 110; 92]
  댓글 수: 2
the cyclist
the cyclist 2015년 9월 29일
Royvg94, I have noticed you asking a series of very straightforward questions in this forum, over the course of the last several days. These look very much like homework problems to me. Maybe they are, and maybe they aren't.
If they are, I would just like to caution you. It might seem like you are learning MATLAB this way, but you are not. Even if you feel like, "Oh, now I understand how that works", the learning is simply not the same as figuring it out for yourself.
If these questions are homework, I would encourage you to
  • spend more time struggling on them yourself
  • clearly identify your questions here as homework problems
  • post your code here to get hints, instead of answers
You will find that people here are very willing to help you learn.
Royvg94
Royvg94 2015년 9월 30일
편집: Royvg94 2015년 9월 30일
It's not homework, im using Matlab to analyse data from an experiment I'm running. You got a point that I'll probably find my answers myself, but it would be a huge waste of time, cause I'm not familiar with Matlab.. Im writing a script to analyse these data, and theres just some steps I need to know, which take a lot of time if I would have to figure them out myself, and I have better things to do instead of wasting time on that.

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2015년 9월 29일
B = sum(A(:,[2,4]),2);

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by