0
votes

I'm running parfor loop that returns matrix with different dimensions at each iteration, I need these matrices to be concatenated for the final result

for example

T = [1 2 3 0
  7 8 9 10]

I compute for each row the maximal block which should return

for the first row

 [1 2
1 3] 

and for the second row

[7 8 9 
 7 9 10]

my code is

parfor i = 1:size(T,1)
   findMBL(Data,T(i,:));
end

where findMBL is the function that returns the blocks. my problem is how can i concat the results of the iterations in one matrix

The result should be

[1 2 0
1 3 0
7 8 9
7 9 10]

Note: zero in row 1 and 2 is padding

2
In general, you dont need to worry about anything while using parallel toolbox. If there is somethign to worry about generally Matlab will ut a warning. - Ander Biguri

2 Answers

0
votes

if you know the maximum size of the result, its easy to do.

% I am completely guessing this, substitute for realistic maximum possible size
res=zeros(2*size(T,1),size(T,2)); 


parfor i = 1:size(T,1)
   auxres=findMBL(Data,T(i,:));
   res([i*2-1,i*2],1:size(auxres,2))=auxres;
end
-1
votes

You have to define a buffer cell, in which you will put your arrays at each iteration, and then use cell2mat to obtain the concatenated result.