Can someone do this calculation without for loops ?

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 日

0 投票

k = bsxfun(@times, a , reshape(b.^2,1,1,[]))
alt_k = bsxfun(@times, a , permute(b.^2,[3,1,2]))

1 件のコメント

Amelos
Amelos 2016 年 6 月 15 日
this one works also , thanks k = reshape(kron(b.*b,a),[size(a),numel(b.*b)]);

サインインしてコメントする。

その他の回答 (2 件)

Joakim Magnusson
Joakim Magnusson 2016 年 6 月 15 日

0 投票

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 日

0 投票

a = [1 2 3; 4 5 6];
b = [ 1 2 3];
bb=reshape(b.*b,1,1,[])
out=bsxfun(@times,a,bb)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2016 年 6 月 15 日

編集済み:

2016 年 6 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by