Dear Prof/Dr./Sir./Maam
I have matrix A=[1 2 3 4 5] and B=[ 6 7 8 9]. I want to calculate s1=1+2+6 s2=2+3+7 s3=3+4+8 s4=4+5+9.
Is it possible to calculate the elements from different matrix like that?
Thank you in advance

 채택된 답변

sudobash
sudobash 2022년 7월 29일
Hi!
So as per my understanding, 2 consecutive elements of A need to be added and the resulting vector needs to be added to B.
A possible solution could be like this:
A=[1 2 3 4 5];
B=[ 6 7 8 9];
Asum = A(2:end) + A(1:end-1)
Asum = 1×4
3 5 7 9
final = Asum + B
final = 1×4
9 12 15 18
Hope this solves your question.

댓글 수: 1

Noriham B
Noriham B 2022년 7월 29일
Great....so much thanks to u prof/Dr/Sir...I can run the results now...really appreciate ur help

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

추가 답변 (0개)

카테고리

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

제품

릴리스

R2014a

질문:

2022년 7월 29일

댓글:

2022년 7월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by