Can someone do this calculation without for loops ?

1 次查看(过去 30 天)
a = [1 2 3; 4 5 6];
b = [ 1 2 3];
for n = 1: size(a,1)
for m = 1:size(a,2)
k(n,m,:)= b.*b*a(n,m)
end
end

采纳的回答

José-Luis
José-Luis 2016-6-15
编辑:José-Luis 2016-6-15
k = bsxfun(@times, a , reshape(b.^2,1,1,[]))
alt_k = bsxfun(@times, a , permute(b.^2,[3,1,2]))

更多回答(2 个)

Joakim Magnusson
Joakim Magnusson 2016-6-15
Do you mean like this?
fun=@(a,b) b.*b*a
k = bsxfun(fun,a,b)

Azzi Abdelmalek
Azzi Abdelmalek 2016-6-15
编辑:Azzi Abdelmalek 2016-6-15
a = [1 2 3; 4 5 6];
b = [ 1 2 3];
bb=reshape(b.*b,1,1,[])
out=bsxfun(@times,a,bb)

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by