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!