i want to multiply
L(:,:,k,:).*M(:,:,k,:);
i want to multiply without loop.

 採用された回答

Christine Tobler
Christine Tobler 2015 年 12 月 17 日
編集済み: Christine Tobler 2015 年 12 月 17 日

0 投票

You could try downloading the tensor toolbox by Kolda and Bader, where this is provided as a command ttt(L, M, 3, 3). Alternatively, you can use the following code:
permL = permute(L, [3 1 2 4]);
permM = permute(M, [3 1 2 4]);
szL = size(L);
szM = size(M);
result = permL(:, :)'*permM(:, :);
result = reshape(result, [szL([1 2 4]), szM([1 2 4])]);
This returns a 6-dimensional array result, such that
result(i1, i2, i3, j1, j2, j3)
is the same as
a = 0; for k=1:size(L, 3), a = a + L(i1, i2, k, i3)*M(j1, j2, k, j3); end; a
Is this what you wanted to compute?

2 件のコメント

Triveni
Triveni 2015 年 12 月 18 日
編集済み: Matt J 2016 年 1 月 20 日
plyangle = [45 45 45 45 45 45 0 0 0 0 0 0 0 0 45 45 45 45 45 45];
N1 = 2;
p1 = randi(numel(plyangle), [1 20 N1]);
plyangle = plyangle(p1);
for i= 1:2
for k = 1:20
a(:,:,i,k)= cosd (plyangle(:,k,i));
b(:,:,i,k)= sind (plyangle(:,k,i));
L(:,:,k,i) = [a(:,:,i,k)*b(:,:,i,k) 0 (a(:,:,i,k))^2;
0 0 b(:,:,i,k);
a(:,:,i,k)*b(:,:,i,k) 0 0;];
M(:,:,k,i) = [a(:,:,i,k)*b(:,:,i,k) 0 (a(:,:,i,k))^2;
0 0 b(:,:,i,k);
a(:,:,i,k)*b(:,:,i,k) 0 0;];
end
end
can you correct this?? I think it's wrong.
Christine Tobler
Christine Tobler 2015 年 12 月 18 日
I'm not sure what you want L and M to be, can you explain in more detail?

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 12 月 17 日

1 投票

L.*M
Somehow I suspect that your question missed some information...

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

質問済み:

2015 年 12 月 17 日

編集済み:

2016 年 1 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by