필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Build the sum fom only a few coloumns of a matrix.

조회 수: 1 (최근 30일)
Benedikt Wessel
Benedikt Wessel 2019년 6월 3일
마감: MATLAB Answer Bot 2021년 8월 20일
Hello everybody.
A=[1,2,3,4,5,6,7,8,9,10;1,2,3,4,5,6,7,8,9,10;1,2,3,4,5,6,7,8,9,10;] % not a fixed size, can be build with n*5
How can I build the sum of five numbers? I don´t know which algorithm or function to use, if the length of the matrix is unknown(rows are multiple times 5 and normally the numbers are randomnly generated).
B=[15,40;15,40;15,40] % wanted output
Can you help me putting this operation into a for loop, so that I can do it on every size of the matrix?
Thanks.
  댓글 수: 1
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 6월 3일
편집: KALYAN ACHARJYA 2019년 6월 3일
Same question
"Can you help me putting this operation into a for loop"-
You accepted the answer too.

답변 (1개)

Raj
Raj 2019년 6월 3일
n=input('Enter number of rows:');
A=rand(n,10);
B=zeros(n,2);
for x=1:n
B(x,1)=sum(A(x,1:5));
B(x,2)=sum(A(x,6:10));
end
display('The required matrix is:')
B

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by