Element wise multiplication to matrix in a "matrix array"?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have an array of matrix m such that
m1 = [1 2;3 4];
m2 = [2 7; 8 9];
m3 = [9 7; 8 91];
m = [m1 m2 m3]
m =
1 2 2 7 9 7
3 4 8 9 8 91
I also have a vector
v = [1 2 3];
such that i want the operations between v and m result in h such that
h = [1*m1 2*m2 3*m3] = [h1 h2 h3];
From h i want to extract h1 h2 and h3 out(, how?) such that
h1*A*h1'
h2*A*h2'
h3*A*h3'
and where A is a 2 by 2 matrix, say [10 11; 12 13].
h1*h1', h2*h2', h3*h3'.
The reason i want to do this in array is because i have a lot of matrix mi so I want to avoid for loop by vectorization.
Risposte (1)
Azzi Abdelmalek
il 27 Ago 2016
m1 = [1 2;3 4];
m2 = [2 7; 8 9];
m3 = [9 7; 8 91];
m = [m1 m2 m3]
[n1,n2]=size(m1)
v=[1 2 3]
M=reshape(m,n1,n2,[])
B=bsxfun(@times,M,reshape(v,1,1,[]))
out=B(:,:)
0 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!