Hey all, I need to store an array in every element of the array I have, how do i do this?

Example: For an array say x, I want every element in x to have an array. so x(1,1) will have an (m X n) matrix and so on.

 採用された回答

Mohammad Abouali
Mohammad Abouali 2015 年 10 月 16 日
編集済み: Mohammad Abouali 2015 年 10 月 16 日
Use cell array like this
X=cell(3,3);
X{1,1}=rand(3,2);
X{2,1}=rand(5,7);
and so on

3 件のコメント

Aditya
Aditya 2015 年 10 月 16 日
Thanks for the reply Mohammad, but my main array does not have a predefined size, it keeps incrementing.
X = {};
K = 0;
while rand() <= 0.93
K = K + 1;
n = randi(50);
X{K} = rand(1,n);
end
There, a cell of indefinite length, with each cell member being of potentially different size. Adapt as needed.
Mohammad Abouali
Mohammad Abouali 2015 年 10 月 16 日
編集済み: Mohammad Abouali 2015 年 10 月 16 日
Then don't predefine it. You can either give it a blank cell array as walter said in above post, or you can start with something like this:
x{1,1}=rand(3,2)
x =
[3x2 double]
x{3,5}=rand(4,6)
x =
[3x2 double] [] [] [] []
[] [] [] [] []
[] [] [] [] [4x6 double]
x starts to expand and it grows. However, due to performance issue it is not recommended. But if that's what needed then that's what is needed.

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

その他の回答 (0 件)

カテゴリ

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

質問済み:

2015 年 10 月 15 日

編集済み:

2015 年 10 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by