Alternate to repmat to create cell array

19 ビュー (過去 30 日間)
Aditya Jain
Aditya Jain 2015 年 11 月 9 日
コメント済み: Aditya Jain 2015 年 11 月 9 日
Currently I am using repmat to create a matrix of multiple struct
structElement = struct('a1','', 'a2', '', 'a3', '', 'a4', '');
s1 = repmat(structElement, [1,2]);
This creates a 1x2 struct
Is there a method which can create a cell array instead of matrix
basically
CellArray =
[1x1 struct] [1x1 struct]

採用された回答

Kelly Kearney
Kelly Kearney 2015 年 11 月 9 日
You can use deal to assign a variable to every element of a cell array:
structElement = struct('a1','', 'a2', '', 'a3', '', 'a4', '');
x = cell(1,2);
[x{:}] = deal(structElement)
x =
[1x1 struct] [1x1 struct]
  1 件のコメント
Aditya Jain
Aditya Jain 2015 年 11 月 9 日
Worked well. Thanks

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by