cannot assign values to a cell during a parfor loop
조회 수: 1 (최근 30일)
이전 댓글 표시
I'm trying to evaluate the output of a high number of url in my domain, but I cannot deal with the "parfor" loop rules.
I get the following error:
Error: Unable to classify the variable 'checklist' in the body of the parfor-loop. For more information, see Parallel for Loops in MATLAB, "Solve Variable Classification Issues in parfor-Loops".
fold_list = cellstr(strcat('Folder_',num2str((100:125).','%#4.d')));
user_lists = cellstr(strcat('User_',num2str((1:100).','%#6.d')));
base_url = 'https://mydomain.com';
n_folds = length(fold_list);
n_users = length(user_lists);
checklist = cell(n_users+1,n_folds+1);
checklist(2:end,1) = user_lists;
checklist(1,2:end) = fold_list;
parfor j=1:n_users
for k=1:n_folds
try
checklist{j+1,k+1} = webread([base_url '/' fold_list{k} '/' user_lists{j} '.txt']);
catch
checklist{j+1,k+1} = 'N/A';
end
end
end
댓글 수: 0
채택된 답변
Jan
2022년 7월 15일
편집: Jan
2022년 7월 15일
Try this:
fold_list = cellstr(strcat('Folder_',num2str((100:125).','%#4.d')));
% By the way: Simpler:
% fold_list = sprintfc('folder_%03d', (100:125).'):
user_lists = cellstr(strcat('User_',num2str((1:100).','%#6.d')));
base_url = 'https://mydomain.com';
n_folds = length(fold_list);
n_users = length(user_lists);
checklist = cell(n_users+1,n_folds+1);
checklist(2:end,1) = user_lists;
checklist(1,2:end) = fold_list;
C = cell(n_users,n_folds)
parfor j=1:n_users
for k=1:n_folds
try
C{j,k} = webread([base_url '/' fold_list{k} '/' user_lists{j} '.txt']);
catch
C{j,k} = 'N/A';
end
end
end
cecklist(2:end, 2:end) = C;
댓글 수: 5
Bruno Luong
2022년 7월 17일
편집: Bruno Luong
2022년 7월 17일
Humm it exists on mine
>> ver
-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.12.0.1975300 (R2022a) Update 3
MATLAB License Number: xxxxxx
Operating System: Microsoft Windows 11 Home Version 10.0 (Build 22000)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB Version 9.12 (R2022a)
MATLAB Coder Version 5.4 (R2022a)
MATLAB Compiler Version 8.4 (R2022a)
Optimization Toolbox Version 9.3 (R2022a)
Parallel Computing Toolbox Version 7.6 (R2022a)
Signal Processing Toolbox Version 9.0 (R2022a)
>> sprintfc('%f', [1:3]) % yeah close your eyes master
ans =
1×3 cell array
{'1.000000'} {'2.000000'} {'3.000000'}
>> which sprintfc
built-in
>>
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!