Multiplication of elements in array
Mostra commenti meno recenti
Hi everyone, I have b=[1 1 1; 1 2 4; 1 3 9; 1 4 16] and k=1:5, I want to have 4 different set of numbers.
There are total 4 rows in set b.
To form the first set of number which denoted as kb1, I take the numbers from first row from set b, which is [1 1 1].
For the first row of kbl=k(1)*[1 1 1]
For the second row of kb1=k(2)*[1 1 1]
For the third row of kbl=k(3)*[1 1 1]
For the fourth row of kb1=k(4)*[1 1 1]
And finally for the fifth row of kbl=k(5)*[1 1 1].
Next follow by second set of the numbers,which denoted as kb2=k*[1 2 4]
So at the last I will have 4 set of numbers,
How can i do this?
Thanks
Risposta accettata
Più risposte (1)
Andrei Bobrov
il 12 Mag 2014
Modificato: Andrei Bobrov
il 12 Mag 2014
kb = bsxfun(@times,permute(b,[3,2,1]),k(:));
add
kb = num2cell(bsxfun(@times,permute(b,[3,2,1]),k(:)),[1 2]);
kb_cell = kb(:);
Categorie
Scopri di più su Linear Algebra in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!