필터 지우기
필터 지우기

Using pagemtimes multiplying from left and right side

조회 수: 4 (최근 30일)
Morten Nissov
Morten Nissov 2021년 5월 3일
답변: Felipe Padua 2022년 8월 29일
I have a 3D array I need to multiply on left and right sides by a constant 3x3 matrix, take a cholesky decomposition and multiply it by a random vector, I am trying to avoid for loops. The arrays are P 6x6xN and F 3x6. The equivalent for loop multiplication is
for i=1:length(Pf)
w = chol(Fn*Pf(:,:,i)*Fn')*randn(3,1);
out(:,i) = out(:,i) + w;
end

답변 (1개)

Felipe Padua
Felipe Padua 2022년 8월 29일
You can use pagemtimes to perform both multiplications but, since chol accept only matrices (2D arrays) as arguments, you'll still need a loop. Try the code below:
n = size(Pf, 3);
aux = pagemtimes(Fn, Pf);
aux = pagemtimes(aux, Fn');
for i = 1:n
aux (:,:,i) = chol(aux(:,:,i));
end
aux = pagemtimes(aux, rand(3,1,n));
If you desire retrieve the steps taken, you may avoid overwriting the aux variable renaming the sucessive results as aux1, aux2 etc, or other names of your preference.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by