MATLAB nested parfor indexing

63 views Asked by At

I converted a nested for loo into a unique parfor loop. The nested for loop looked like this:

for RIPETIZIONE = 1:N_RIPETIZIONI
   for k=1:size(lambda_tol_vector)
       %do things
   end
end

Now, the parfor loop takes on the following values:

parfor n=1:N_RIPETIZIONI*K
   [~,k]=ind2sub([N_RIPETIZIONI,K],n);
...

hence merging into a single loop the nested loops of before. Now, inside the "outer" nested loop (for RIPETIZIONE = 1:N_RIPETIZIONI), but outside the inner loop (for k=1:size(lambda_tol_vector)), there was this part:

scv=size(columns_validation_test,2);   
   
for counter_columns = 1:scv
   COLONNA_SELEZIONATA=columns_validation_test(counter_columns);
   Ctest=zeros(size(A.Value));
   Ctest(:,COLONNA_SELEZIONATA)=C(:,COLONNA_SELEZIONATA);
   Cvalidation=C-Ctest;
   for j=1:size(lambdavector)
       RMSE_initial_test{counter_columns}(j)=sqrt(sum2(Diff_sq_initial{j}.*Ctest)/sum(Ctest(:)));
       RMSE_final_corrected_validation{counter_columns}(j)=sqrt(sum2(Diff_sq_corrected{j}.*Cvalidation)/sum(Cvalidation(:)));
       RMSE_final_test{counter_columns}(j)=sqrt(sum2(Diff_sq{j}.*Ctest)/sum(Ctest(:)));
       RMSE_final_corrected_test{counter_columns}(j)=sqrt(sum2(Diff_sq_corrected{j}.*Ctest)/sum(Ctest(:)));
           
   end
       [~,arg_min_temp_1]=min(RMSE_final_corrected_validation{counter_columns});
end

which I need now to include in the unique parfor loop with a pope indexing. Fo instance, Diff_sq_initial, Diff_sq_corrected and Diff_sq are all defined within the parfor loop with an index of n in the new loop (whereas previously they were indexed with k inside the for k=1:size(lambda_tol_vector) loop). Is there a way to properly indexing those variables so that they fit the new parfor loop?

0

There are 0 answers