I am trying to speed up a script that I have written in Matlab that dynamically allocates memory to a matrix (basicallly reads a line of data from a file and writes it into
If you want to stick to your code as written I would substitute your initialization of data, data = []
to
data = zeros(1,1000);
Keep in mind though the warning from @MZimmerman6: zeros(1000)
generates a 1000 x 1000 array. You may want to change all of your zeros
statements to zeros( ... ,Nc)
, where Nc = length of line in characters.