フィルターのクリア

cannot assign values to a cell during a parfor loop

1 回表示 (過去 30 日間)
endystrike
endystrike 2022 年 7 月 15 日
編集済み: endystrike 2022 年 7 月 17 日
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 Center および File ExchangeParallel 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