Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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

1 Ansicht (letzte 30 Tage)
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?

Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by