Multiply Constant Array by Another Cell Array

3 Ansichten (letzte 30 Tage)
Kareem Elgindy
Kareem Elgindy am 9 Jan. 2023
Beantwortet: Stephen23 am 9 Jan. 2023
How to multiply each element of [2 3] by {(1:3)';(-1:2)'} so that the output is {[2,4,6]';[-3,0,3,6]'}?

Akzeptierte Antwort

Stephen23
Stephen23 am 9 Jan. 2023
A = {(1:3).';(-1:2).'};
B = [2,3];
C = cellfun(@times,A,num2cell(B(:)), 'uni',0)
C = 2×1 cell array
{3×1 double} {4×1 double}
C{:}
ans = 3×1
2 4 6
ans = 4×1
-3 0 3 6

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by