Setting up an array which has a 4x1 matrix in each one of it's cells

31 views (last 30 days)
Hi,
Would anyone be able to give me any help on how to set up a 10x10 array such that each cell within this array is a 4x1 matrix? I'm not sure if this is the correct terminology or if it's called something else. However my basic problem is that I'm calculating something within 2 loops (both with 10 cycles hence the 10x10) and want to record the result in an array/matrix for each case so that it may be stored. The value I want to store is a 4x1 matrix.
Thanks in advance,
Nick
  1 Comment
James Tursa
James Tursa on 7 Feb 2013
This often doesn't make sense except in special circumstances (e.g., modifying each cell's data area in-place downstream in your code). If you are replacing each cell element downstream in your code with another 4x1 matrix, then this pre-allocation is just a waste of time. What are you doing with this cell array downstream in your code?

Sign in to comment.

Accepted Answer

Wayne King
Wayne King on 7 Feb 2013
Edited: Wayne King on 7 Feb 2013
One way:
X = cell(10,10);
X = cellfun(@(x) zeros(4,1),X,'uni',0);
Now you see with
cellplot(X)
that each cell is a 4x1 vector of zeros.

More Answers (2)

Jan
Jan on 7 Feb 2013
X = cell(10,10);
X(:) = {zeros(4, 1)};

Jos (10584)
Jos (10584) on 7 Feb 2013
X = repmat({zeros(4,1)},10,10)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!