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

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 件のコメント

James Tursa
James Tursa 2013 年 2 月 7 日
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?

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

 採用された回答

Wayne King
Wayne King 2013 年 2 月 7 日
編集済み: Wayne King 2013 年 2 月 7 日

0 投票

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.

3 件のコメント

Nick
Nick 2013 年 2 月 7 日
Excellent, thank you!!!
Jos (10584)
Jos (10584) 2013 年 2 月 7 日
the used of cellfun is rather over the top here ...
Nick
Nick 2013 年 2 月 7 日
Thanks for that, I've now changed my code to yours, Jos, thank you very much!

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

その他の回答 (2 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by