Parfor converting object to double?

조회 수: 2 (최근 30일)
David K
David K 2021년 4월 15일
답변: Edric Ellis 2021년 4월 16일
I am trying to parallelize some of my code to make it run quicker and ran into a weird error that I get in 2019a but not in 2020b. The error states:
The following error occured converting DataObj to double: Converstion to double from DataObj is not possible.
This doesn't happen when I am running serially with a for loop instead. If I set DataObj.double to output a double, then I get the error Assertion failed in consume_assign at line 24. A simplified version of my code is below.
Why am I seeing this in older versions, and is there a way to fix this to work on older versions?
dataSet = repmat(DataObj.empty(),1,N);
for ii = 1:N
dataSet(ii) = DataObj(info(N));
end

채택된 답변

Edric Ellis
Edric Ellis 2021년 4월 16일
In older versions that exhibit the problematic behaviour, your best bet is probably to use a cell, like so:
N = 3;
resultCell = cell(1, N);
parfor i = 1:N
resultCell{i} = MException('dummy:exception', 'Just for this example');
end
result = [resultCell{:}]
result =
1×3 MException array with properties: identifier message cause stack Correction

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by