I loaded the .mat file and use the variables in the rest of the codes. Even though the file is loaded outside the for loop, it shows the variable is not defined during the calculation, moreover, the very same variable is used in even earlier calculation. I think the problem is caused by the parfor, so I would like to set the loaded variables as global to see if the problem can be solved.
The part of the code is
load('SobolParameter3Layer.mat');%input: numLayer numPar N Par Para Parac AllCol numCol totalCol
for j=1:numPar comb=AllCol{j}; SF=zeros(N,size(AllCol{j},1));WF=zeros(N,size(AllCol{j},1)); parfor i=1:size(comb,1) para=Par(:,1+numPar:2*numPar); para(:,comb(i,:))=Par(:,comb(i,:)); [SF(:,i),~,WF(:,i)]=BandStruS(para,numLayer); end Start(:,numCol(1,j):numCol(2,j))=SF;Width(:,numCol(1,j):numCol(2,j))=WF;end
the code can run without problem for the first for loop, but when it comes to parfor, the "numPar" becomes undefined.
Best Answer