MATLAB: Pre allocating triple loops preallocating hi, how to pre-allocate this: for ii = 1:numel(L); for jj=1:numel(L); for kk=1:45; c=cross(L1(ii,:),a{jj}(kk,:)); end end end Best Answer n = numel(L);c = cell(n,n,45);for ii = 1:n for jj = 1:n for kk = 1:45 c{ii,jj,kk} = cross(L1(ii,:),a{jj}(kk,:)); end end end Related SolutionsMATLAB: Pre allocating vector for loop c1 = cell(numel(a11),1); % before loop use numel instead of lengthc1{ii} = ... inside loop MATLAB: Question on updating a matrix Did you pre-allocate L and seccost before the loop?L = false(n, n);seccost = zeros(n, n); Related QuestionStoring and passing all iterations to an array outside the nested for loopsMoving window with cumulative sum less than a ref value and excluding certain windowsRow filtering and pre-allocateError using fzero ” FUN must be a function, a valid string expression, or an inline function object”Save matrix of each iterationReshape loop resulted cell array
Best Answer