Hi everyone,
Suppose I have a matrix:
a = [4 2 1;1 9 6;4 22 4;12 15 1;1 6 8;5 2 6];
I want to summing every two rows together and write in matrix b:
Such as:
b= [23; 58; 28]
details of calculation:
23 = a (1,:) + a (2,:)
58 = a (3,:) + a (4,:)
28 = a (5,:) + a (6,:)
Can anyone help me please?

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 26일
편집: Azzi Abdelmalek 2014년 4월 26일

0 개 추천

a = [4 2 1;1 9 6;4 22 4;12 15 1;1 6 8;5 2 6]
b=sum(reshape(a',2*size(a,2),[]))

댓글 수: 1

Moe
Moe 2014년 4월 26일
Thank you Azzi, just one transpose was needed in the last.

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

추가 답변 (1개)

Roger Stafford
Roger Stafford 2014년 4월 26일

0 개 추천

b = sum(reshape(a.',2*size(a,2),[]),1).'; % Assume an even no. of rows

카테고리

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

태그

질문:

Moe
2014년 4월 26일

댓글:

Moe
2014년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by