## add two matrixes with different dimensions line by line

Jaap Rijnders

### Jaap Rijnders (view profile)

님이 질문을 제출함. 21 Jun 2019
최근 활동 Jaap Rijnders

### Jaap Rijnders (view profile)

님이 댓글을 추가함. 21 Jun 2019
infinity

### infinity (view profile)

님이 답변을 채택함.
Hi,
Please some assistance with my following problem:
I am trying to add two matrixes that have diffent dimensions.
I have the following matrixes
• a = [2 3;1 3;2 4]
• PosPath =[ 1 -1;0 -1;-1 -1; 1 0; -1 0; 1 1; 0 1; -1 1];
and I want the outcome in Outcome as if [a(1,:)+Pospath ; a(2,:)+Pospath ;a(3,:)+Pospath]
I tried:
********************
for i=1:size(a,1)
c = a(i,:)+PosPath;
end
**********************
but this only captures the last statement (a(3,:)+Pospath).
So, my question is: What do I have to change to the code to get the matrix Outcome?

infinity

### infinity (view profile)

21 Jun 2019
Hello,
Have you tried what you want like this
Outcome = [a(1,:)+PosPath ; a(2,:)+PosPath ;a(3,:)+PosPath]
It is exactly what you mentioned before.
Jaap Rijnders

### Jaap Rijnders (view profile)

21 Jun 2019
Hi Trung,
true, but... the the number of rows of 'a' can vary.
KALYAN ACHARJYA

### KALYAN ACHARJYA (view profile)

21 Jun 2019
@Jaap It would be great, if you show us the addition of following two matrices
A=[1 2 3 4; 5 6 7 8];
B=[2 3 4;6 7 8;8 10 11];

로그인 to comment.

R2018b

## 답변 수: 1

infinity

### infinity (view profile)

님의 답변 21 Jun 2019
채택된 답변

Hello,
So, it coul be like that
clear
a = [2 3;1 3;2 4]
PosPath =[ 1 -1;0 -1;-1 -1; 1 0; -1 0; 1 1; 0 1; -1 1];
c = [];
for i=1:size(a,1)
c = [c; a(i,:)+PosPath];
end

Jaap Rijnders

21 Jun 2019
Thanks!

로그인 to comment.

Translated by