Multiplying arrays to add a dimenstion

4 ビュー (過去 30 日間)
Drew Elliott
Drew Elliott 2020 年 7 月 29 日
編集済み: Drew Elliott 2020 年 7 月 29 日
Hello,
I have a big array which represents a vector field on a surface. It's dimensions are 3xNxN. I would like to project that surface forward along these vectors, along a distance of M. So I'd like to multiply the arrays M by 3xNxN to wind up with a new array that's Mx3xNxN. I've tried a bunch of different kinds of multiplication. Do I have to give each array an extra dimension of 1? I think I could do it then, but I don't know of an easy way to add a dimension of length 1.
I know how to do this with a loop. I was hoping that there is some faster/easier way to do it with matrix operations.
  2 件のコメント
James Tursa
James Tursa 2020 年 7 月 29 日
What does "project along a distance of M" mean? Do you have an M-element vector that you are multiplying by? Or ...?
Drew Elliott
Drew Elliott 2020 年 7 月 29 日
編集済み: Drew Elliott 2020 年 7 月 29 日
Essentially yes. I want to multiply an M vector by a 3xNxN array and get an Mx3xNxN array. The actual physics that it represents aren't really important to the Matlab Question, but if you're interested:
The vector field is made up of unit vectors, so what I'm really doing is adding M_i .* 3xNxN (vector) to 3xNxN (original position) to get p_i 3xNxN. Each p_i 3xNxN is a projection of the original surface along the vector field through the distance M_i.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 7 月 29 日
permute(TheArray, [4 1 2 3]) .* TheVector(:)
The result will be numel(TheVector) by size(TheArray,1) by size(TheArray,2) by size(TheArray,3)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by