MATLAB: Add two matrixes with different dimensions line by line

add/plus matrixes different dimensionsMATLAB

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?
Thanks in advance!

Best Answer

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