hi guys i

1 comentario

Intisar Mohammed
Intisar Mohammed el 31 de Mayo de 2020
Addition of two square matrices 𝐴 𝑎𝑛𝑑 𝐵 of same order.

Iniciar sesión para comentar.

 Respuesta aceptada

Roger Stafford
Roger Stafford el 18 de Oct. de 2014

2 votos

Let 'a' and 'b' be two row vectors. To add zeros to the left side of the shorter one so as to have equal lengths do this:
na = length(a);
nb = length(b);
n = max(na,nb);
a2 = [zeros(1,n-na),a];
b2 = [zeros(1,n-nb),b];

4 comentarios

janny
janny el 18 de Oct. de 2014
how to make it run for two matrix with 10 or more vectors? i try it it didn't work for matrix.
Roger Stafford
Roger Stafford el 18 de Oct. de 2014
Editada: Roger Stafford el 18 de Oct. de 2014
Let 'a' and 'b' be two matrices with the same number of rows, m.
na = size(a,2);
nb = size(b,2);
n = max(na,nb);
a2 = [zeros(m,n-na),a];
b2 = [zeros(m,n-nb),b];
(It should be obvious how to also deal with matrices with both differing numbers of columns and differing numbers of rows.)
janny
janny el 18 de Oct. de 2014
it works very fine.. thanks a lot
Image Analyst
Image Analyst el 18 de Oct. de 2014
Can you go ahead and officially "Accept" his answer and also "vote" for it to give him credit/reputation points for it? Thanks in advance.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 18 de Oct. de 2014

Comentada:

el 31 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by