I have a problem regarding the use of a for loop. I would like to avoid this loop in order to have a faster execution of my code.
I have a vector of cells called str_cell. The length of the vector is NUM_LINES = 300. Each cell contains a string of 11 numbers in a string format, which are delimited by a TAB.
In the for loop I convert the cells in vectors of numbers and I pass them in an array, called data, which has been previously initialized.
Here the code
for i = 1:NUM_LINES numbers = str2double(strread(str_cell{i},'%s','delimiter','\t')); data(i, :) = numbers(:);end
When NUM_LINES is 300, my computer takes ~290ms to do that. I tried to avoid the for loop, but the command str2double works with a single string so that I had to pass cell by cell. Moreover I cannot change the way to get the files, in order to by-pass the problem. Do you have suggestions about avoiding this for loop?
Thanks in advance
Best Answer