MATLAB: Preallocate an matrix in 2 for loops MATLABpreallocate How would I preallocate This matrix? for j=1:numel(A) for i=1:numel(A) B(j,i)="Calculation here" endend Best Answer N=numel(A);B=zeros(N,N); %This is howfor j=1:N for i=1:N B(j,i)="Calculation here" endend Related SolutionsMATLAB: What does for j = [1:i-1, i+1:n] mean for j = [1:i-1, i+1:n] ...endis the same as:for j = 1:n if j ~= i ... endendIt runs a loop over all numbers from 1 to n, but excludes i . The loop index is the concatenation of the vectors 1:i-1 and i+1:n .You can simply try it:n = 10;i = 7;for j = [1:i-1, i+1:n] disp(j)end MATLAB: Vectorize nested for loops Jacobian=D2Mat(2:end-1,:)+(2./XCheb(2:end-1)).*D1Mat(2:end-1,:)+((xi^2)*n*Y(2:end-1).^(n-1)).*D0Mat(2:end-1,:); Related QuestionPre-allocating structuresNested Struct Preallocated MemoryHaving Trouble With PreallocatingAbout Preallocating for speed
Best Answer