MATLAB Answers

Attempt to grow array along ambiguous dimension.

78 ビュー (過去 30 日間)
Nour Ellouze
Nour Ellouze 2019 年 2 月 2 日
回答済み: OCDER 2019 年 2 月 2 日
Hello,
I have a probleme with a creation of a song and the error "Attempt to grow array along ambiguous dimension" appears

  0 件のコメント

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

回答 (1 件)

OCDER
OCDER 2019 年 2 月 2 日
A = zeros(3, 3, 3); % There are 27 elements in A in a 3x3x3 matrix
A(3^3+1) = 1;
%ERROR: Attempt to grow array along ambiguous dimension.
% Where do you want the 28th element to go?
% Do you want a 4x3x3, 3x4x3, or 3x3x4 matrix in the end?
Error is caused when you try to add an element to a matrix outside the original dimensions. Matlab automatically grows the array to make this happens, but in this case, it doesn't know which dimension to add your new value.
BUT, you shouldn't be growing arrays in the first place as it's a bad coding practice prone to slow codes. Essentially, Matlab has to copy your array to a new size and delete the previous array every time.

  0 件のコメント

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by