How to apply operations (add/subtract) to only a certain row range between 2 matrics?

1 回表示 (過去 30 日間)
hithere
hithere 2014 年 12 月 18 日
編集済み: hithere 2014 年 12 月 18 日
Lets say I have 2 matrics with n rows:
A = 1 2 6
3 5 6
2 4 6
.
.
.
3 3 1
B = 1 5 6
2 5 7
8 5 3
.
.
.
3 4 5
And I want to add Row 2 to Row (n) of both matrics up (skipping row 1)
I know for this the coding should be:
.
C = A(2:n,:) + B(2:n,:)
.
So the result be like:
C = - - -
5 10 13
10 9 9
.
.
.
6 7 6
and after that another matric is to add Row 1 and, Row 3 to Row (n), of both matrics (skipping row 2)
D = 2 7 12
- - -
10 9 9
.
.
.
6 7 6
.
then Row 1 and, Row 2 and, Row 4 to Row (n), of both matrics (skipping row 3) .
E = 2 7 12
5 10 13
- - -
.
.
.
6 7 6
all the way to Row 1 to Row (n-1) of both matrics. (skipping last row)
  5 件のコメント
Adam
Adam 2014 年 12 月 18 日
Is this not just the equivalent of:
C = ( n - 1 ) * A + ( n - 1 ) * B;
if you keep adding your results to the result of the previous calculation?
Every row of A will be added to the equivalent row of B (n-1) times, only being missed out of the maths once each. Or am I misunderstanding what you are aiming for?
hithere
hithere 2014 年 12 月 18 日
Sorry Adam, it's not adding up. It should result in different matrics. Eg, C, D, E, F .... So sorry

サインインしてコメントする。

回答 (1 件)

Sarah
Sarah 2014 年 12 月 18 日
編集済み: Sarah 2014 年 12 月 18 日
To add the rows of the matrices, use A(i,:)+B(j,:) where i and j represent your row number.
Happy Coding.
Sarah

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by