how do I vectorize a loop with multi-dimensional arrays/ outer product
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (1)
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);
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!