필터 지우기
필터 지우기

Multiply a set of matrices (3D array) by a vector of values

조회 수: 1 (최근 30일)
SuperNano
SuperNano 2016년 7월 7일
댓글: SuperNano 2016년 7월 7일
I have a 3D array (a) such that size(a) = [n,n,m]. I also have a vector (v) of length(v) = m. I would like to multiply each element from my vector with each 2D matrix in my array. Is there a way to do this without a for loop. To clarify, using a for loop it would be:
for i = 1:m
b(:,:,i) = v(i)*a(:,:,i);
end

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 7일
편집: Azzi Abdelmalek 2016년 7월 7일
% -------Example-----------------
M=randi(3,3,2,4)
v=1:4
%--------------------------------
bsxfun(@times,M,reshape(v,1,1,4))

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by