MATLAB Answers

0

Alternate to repmat to create cell array

Asked by Aditya Jain on 9 Nov 2015
Latest activity Commented on by Aditya Jain on 9 Nov 2015
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]

  0 Comments

Sign in to comment.

1 Answer

Answer by Kelly Kearney
on 9 Nov 2015
 Accepted Answer

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 Comment

Sign in to comment.