adding every element of an array with every element of another array?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Pranav
am 30 Nov. 2012
Bearbeitet: Brandon
am 11 Dez. 2018
dear all, i want to add array elements to every other element of another element of another array in simulink/matlab
0 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 30 Nov. 2012
Pranav wrote: "...i want to add elemnts of A to be added to every other elemnet of B. ie. 1+[5 6 7 8],2+[5 6 7 8],...so on..."
A = [ 1 2 3 4];
B = [ 5 6 7 8];
C = reshape(bsxfun(@plus,A,B.'),1,[]);
0 Kommentare
Weitere Antworten (3)
Vishal Rane
am 30 Nov. 2012
Bearbeitet: Vishal Rane
am 30 Nov. 2012
Do you need to do this in MATLAB code ?
A = [ 1 2 3 4]
B = [ 5 6 7 8]
C = A + B = [ 6 8 10 12 ]
Comment back if your requirement is different.
3 Kommentare
Vishal Rane
am 30 Nov. 2012
arrayfun(@(x)(x+A),B,'Un',0)
will work in that case but output will be a 1x4 cell arrray.
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!