フィルターのクリア

creating multi-dimensional arrays from vectors

3 ビュー (過去 30 日間)
Pal
Pal 2012 年 3 月 27 日
Hi,
I want to create a multi-dimensional array 'b' from a vector 'a' as the following example:
a =
1 2 3 4
b(:,:,1) =
1 1
1 1
b(:,:,2) =
2 2
2 2
b(:,:,3) =
3 3
3 3
b(:,:,4) =
4 4
4 4
Thus I want to copy each entry of 'a' as m by n (2 by 2 in the example) size matrices onto each level of 'b' along the third dimension. I need to avoid element-wise operations and be as fast as possible.
I would appreciate any help.
Thank you.

採用された回答

Geoff
Geoff 2012 年 3 月 27 日
[~,~,b] = ndgrid([0 0], [0 0], a)
  2 件のコメント
Pal
Pal 2012 年 3 月 27 日
Thanks! What are the tilde symbols? I have never seen them in Matlab syntax.
Geoff
Geoff 2012 年 3 月 27 日
They are a placeholder, meaning we don't care about a particular return value. It's the way to get the third return value into 'b' without assigning the first and second return values to a variable.

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

その他の回答 (1 件)

James Tursa
James Tursa 2012 年 3 月 27 日

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by