Prev: How do you make an unavailabe COM port available?
Next: Returning a specified iteration from iterative solvers such as bicgstab
From: Walter Roberson on 14 May 2010 17:53 Joseph wrote: > Consider storing data in a cell array with a double-for loop, thusly: > > count = 0 > for j = 1: n > for i = 1:m > count = count+1; > B{count,1} = {d{j}, ei}, F(i,j) }; > end > end Did you preallocate? Even just B = cell(n*m,1); would be faster than not preallocating. > In any event, I vectorized the problem successfully, but it really > didn't speed things up. Could we see the vectorized version? We might (or might not) see a faster way to do it.
From: Jan Simon on 15 May 2010 10:18
Dear Joseph! > count = 0 > for j = 1: n > for i = 1:m > count = count+1; > B{count,1} = {d{j}, ei}, F(i,j) }; > end > end This line is not valid: B{count,1} = {d{j}, ei}, F(i,j) }; I assume you want this: B{count,1} = {d{j}, e{i}, F(i,j) }; Are you sure, that you want to create a cell, which contains cells: B = {{d{1}, e{1}, F(1, 1)}; {d{1}, e{2}, F(2, 1)}; ...} ?? Perhaps you could reperesent your data faster as: B = {d{1}, e{1}, F(1, 1); d{1}, e{2}, F(2, 1); ...} d{j} does not change in the inner loop, so it is faster to move it outside: B = cell(n * m, 1); count = 0 for j = 1:n dj = d{j}; for i = 1:m count = count+1; B{count} = {dj, e{i}, F(i,j)}; % No need for B{count, 1} end end I'm interested how you have vectorized this. Kind regards, Jan |