Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

how to add matrices with one dimension same and other dimension different such that each element is added to every other element?

1 visualización (últimos 30 días)
I have matrices A=2x2 B=2x4 C=2x2 I want result in a matrix D=2x16 for example
A=[1 3;
2 4]
B=[3 2 4 2;
4 3 6 3]
C=[4 5;
7 5]
D=[(1+3+4) (1+3+5) (1+2+4) (1+2+5) (1+4+4) (1+4+5) (1+2+4) (1+2+5) (3+3+4) (3+3+5) (3+2+4) (3+2+5) (3+4+4) (3+4+5) (3+2+4) (3+2+5);
(2+4+7) (2+4+5) (2+3+7) (2+3+5) (2+6+7) (2+6+5) (2+3+7) (2+3+5) (3+4+7) (3+4+5) (3+3+7) (3+3+5) (3+6+7) (3+6+5) (3+3+7) (3+3+5)]
means that row wise elements are added in resultant. I have a code in which A=2x1 but I can understand how to mold it according to A=2x2 the code is given below
[rows,col_B]=size(B);
[~,col_C]=size(C);
result=zeros(rows,col_B*col_C);
for i=1:col_B
for j=1:col_C
result(:,(i-1)*col_C+j)=A+B(:,i)+C(:,j);
end
end
can anybody tell me the syntax for the output RESULT in this code?

Respuestas (0)

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by