To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016
Hi, would someone happen to know how I could vectorize the following loop?
L=4; for t=1:N; A(:,:,t)=exp(a*(t-1)).*B(:,:,L); end
many thanks, Eli
B1 = B(:,:,4); out = reshape(B1(:)*(0:N-1),[size(B1) N]);
A = bsxfun(@times,exp(bsxfun(@times,a,0:(t-1)),B);
You need to make sure that a, 0:t-1 and B are all in the correct dimensions, and that "times", is the correct multiplication for your needs.
A = bsxfun(@times,exp(bsxfun(@times,a,reshape(0:(t-1),1, 1,),B);