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

조회 수: 3 (최근 30일)
K.E.
K.E. 2016년 8월 27일
답변: Azzi Abdelmalek 2016년 8월 27일
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