Element wise multiplication to matrix in a "matrix array"?

2 次查看(过去 30 天)
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.

回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2016-8-27
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(:,:)

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by