cannot assign values to a cell during a parfor loop

1 visualización (últimos 30 días)
endystrike
endystrike el 15 de Jul. de 2022
Editada: endystrike el 17 de Jul. de 2022
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".

Respuesta aceptada

Jan
Jan el 15 de Jul. de 2022
Editada: Jan el 15 de Jul. de 2022
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 comentarios
Bruno Luong
Bruno Luong el 17 de Jul. de 2022
Editada: Bruno Luong el 17 de Jul. de 2022
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 el 17 de Jul. de 2022
Editada: endystrike el 17 de Jul. de 2022
@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'}

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by