Hello everyone,
I would like to speed-up a code using a parfor loop but my function is not straightforwardly suitable for it. In particular, the problem is the for loop contains a function whose output has a variable length and I need to store all the variable outputs in a final vector.
I can predict the maximum length of the final result, but most likely I will only use one tenth of this maximum.
result = zeros(1,10000);N_result = 0;for i = 1:N result_i = generate_result(i); % This has a variable number of elements
result(N_result+1:numel(result_i) = result_i; N_result = N_result+numel(result_i);end
I would like to use the parfor instead of a for, but I don't know how merge the variable result_i in a single output result. It would be perfect if I could create a variable length vector for each worker, and then merge those vectors.
How can I do this?
Alessandro.
Best Answer