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
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".

采纳的回答

Jan
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
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
>>
endystrike
endystrike 2022-7-17
编辑:endystrike 2022-7-17
@Bruno Luong thanks, I'll try reinstalling Matlab... Maybe something went wrong!
edit: I don't know how and why but now it seems to be working...
>> sprintfc('%04d', magic(3))
ans =
3×3 cell array
{'0008'} {'0001'} {'0006'}
{'0003'} {'0005'} {'0007'}
{'0004'} {'0009'} {'0002'}

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by