Vectorize a nested loop
    4 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Hi all,
is there a way to vectorize the following loop?
for RIPETIZIONE = 1:10
    %for k = 1:size(lambda_tol_vector.Value,1)
    parfor (k = 1:size(lambda_tol_vector.Value,1))
        %fprintf('Completion using nuclear norm regularization... \n');
        [CompletedMat,flag] = matrix_completion_nuclear_GG_vec( ...
               A.Value.*double(B), double(B), N, lambda_tol_vector.Value(k), tol);
        if flag==1
            CompletedMat_parvec{RIPETIZIONE,k}=zeros(size(A));
        end
        CompletedMat_parvec{RIPETIZIONE,k}=CompletedMat;
    end
end
5 件のコメント
採用された回答
  Matt J
      
      
 2022 年 11 月 28 日
        
      編集済み: Matt J
      
      
 2022 年 11 月 28 日
  
      EDITED:
R=10; 
K=size(lambda_tol_vector.Value,1);
CompletedMat_parvec=cell(R,K);
B=double(B);
parfor n=1:R*K
       [RIPETIZIONE,k]=ind2sub([R,K],n);
        %fprintf('Completion using nuclear norm regularization... \n');
        [CompletedMat,flag] = matrix_completion_nuclear_GG_vec( ...
               A.Value.*B,B, N, lambda_tol_vector.Value(k), tol);
        if ~flag
         CompletedMat_parvec{n}=CompletedMat;
        end
end
idx=cellfun('isempty', CompletedMat_parvec);
CompletedMat_parvec(idx)={zeros(size(A))};
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


