Multiply 4D array with 2D array without a for loop
조회 수: 3 (최근 30일)
이전 댓글 표시
I want to compute this:
for i=1:4
f = f+ norm(reshape(i2k(S(:,:,1,i) .* C,[1,2]) - b(:,:,1,i),[sz^2 1]) ,2)^2;
end
Without a for loop. Because we square the norm we can do that:
sum(abs(i2k(S(:,:,1,:) .* C,[1,2])-b(:,:,1,:)).^2);
But I get an error when I do this
S(:,:,1,:) .* C,[1,2]
Can somebody tell me how this is done correctly?
댓글 수: 0
답변 (1개)
KL
2017년 11월 20일
Try this,
bsxfun(@times,S(:,:,1,:),C)
but remember, the result you'll get as a 3D matrix.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!