help in multi dimensional array 3D

5 ビュー (過去 30 日間)
Kawther Alani
Kawther Alani 2017 年 1 月 17 日
コメント済み: Kawther Alani 2017 年 1 月 18 日
hi I'm trying to increase the third dimension in a three-dimensional matrix can you help me? Example a=(2,3,5) after iteration it must be a=(2,3,7) thanks

採用された回答

Greg
Greg 2017 年 1 月 17 日
編集済み: Greg 2017 年 1 月 17 日
I assume that "a=(2,3,5)" means the corresponding length of each dimension of a is 2, 3 and 5.
Increasing variable size is rarely a good idea (there are plenty of articles on pre-allocation; I won't rehash).
a = zeros(2,3,7);
for ind3 = 1:7
a(:,:,ind3) = randi(10,2,3);
end
(But ALL of this trivial example can be done with "a = randi(10,2,3,7);")
If you really MUST dynamically allocate:
  • a(:,:,end+1) = randi(10,2,3); ~OR~
  • a = cat(3,a,randi(10,2,3));
  1 件のコメント
Kawther Alani
Kawther Alani 2017 年 1 月 18 日
thank you

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by