필터 지우기
필터 지우기

how to not violate from trnasparency in parloop? (a good replacement for "which" or "exist")

조회 수: 5 (최근 30일)
Hello!
inside the body of my parloop, I have to evaluate the existance of sth in my workspace then based on that, run a piece of code,
of course this is not working:
if exist('NHP_SoloB')
Actor_B= string(report_struct.unique_lists.B_Name);
else
Actor_A = string(report_struct.unique_lists.A_Name);
end
%
%
loadedDATA = array2table(report_struct.data,'VariableNames',report_struct.header);
if exist('NHP_SoloB')
Rewarded_Aborted = report_struct.unique_lists.B_OutcomeENUM(loadedDATA.B_OutcomeENUM_idx);
else
Rewarded_Aborted = report_struct.unique_lists.A_OutcomeENUM(loadedDATA.A_OutcomeENUM_idx);
end
exist or which can not be used here bc they violates with transparency rules , do you have any suggestion to be consistent with transparency of the workspace?

채택된 답변

Steven Lord
Steven Lord 2024년 5월 7일
How does that variable get created in the workspace? Inside the loop or before? If it gets created inside the loop I'm not sure you'll be able to use parfor at all, as whether or not that variable exists likely depends on which loop iterations have run previously.
Rather than testing for the existence of the variable, can you check for the value of that variable? That could still potentially lead to a violation of loop iteration independence (depending on the exact nature of the calculations you're trying to perform) but it would avoid the transparency rule violation.
  댓글 수: 2
Zahra Yousefi Darani
Zahra Yousefi Darani 2024년 5월 7일
Basically I have two data sets, each of which are a huge structure and the way that I process the data from each is different, before the parloop they are loaded to the main workspace depending on ''input of the user''.
I wanted to say if user loaded the first data set, go through that .... if user loaded the second, go through this... But inevitably I created two seperated parloops for processing the data of each data sets.
Edric Ellis
Edric Ellis 2024년 5월 8일
Maybe it would work to perform the conditional pieces of code ahead of the parfor loop, and have that work with a single named variable? (There can be additional complications other than simply exist when conditionally accessing variables inside parfor which might trip you up).

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by