Matlab:拟合曲线时在parfor中工作for-loop中断
希望你能帮助我解决这个错误。我使用交叉验证机制运行一些代码以适应曲线年龄。我重复曲线拟合1000次以评估最佳拟合。Matlab:拟合曲线时在parfor中工作for-loop中断
我定义我的模型为:
linear_ft = fittype({'x', '1'});
monotonic_ft= fittype({'-1/x', '1'});
quadratic_ft = fittype('poly2');
我然后运行下面通过数据分割的不同选择进行迭代,记录残差以下曲线拟合...
Data = randn(4,300,10,10);
Ages = randn(300,1);
for thisDim1 = 1:4
for thisDim2 = 1:10
for thisDim3 = 1:10
for nIts = 1:1000
RandomOrder = randperm(300,300);
Fit_Subs = RandomOrder(1:length(Ages)/2); % Take random subs to fit to
Test_Subs = RandomOrder(length(Ages)/2+1:300); % Take random subs to test fit to
Fit_Data = squeeze(Data(thisDim1,Fit_Subs,thisDim2,thisDim3)); % Take data to fit to
Test_Data = squeeze(Data(thisDim1,Test_Subs,thisDim2,thisDim3)); % Take data to test fit
Fit_Ages = Ages;
Fit_Ages(Fit_Subs) = []; %Take ages of Fit Subs only
Test_Ages = Ages;
Test_Ages(Test_Subs) = []; % Take ages of Test Subs only
Nsubs = (length(Ages)/2);
% Model Data using Curves
fFit_Lin = fit(Fit_Ages,Fit_Data',linear_ft);
fFit_Mon = fit(Fit_Ages,Fit_Data',monotonic_ft);
fFit_Quad = fit(Fit_Ages,Fit_Data',quadratic_ft);
% Fit Modelled Data to Test Data
tFit_Lin = fFit_Lin(Test_Ages);
tFit_Mon = fFit_Mon(Test_Ages);
tFit_Quad = fFit_Quad(Test_Ages);
% Calculate Median Residual
Lin_Med_Resid(nIts) = median(tFit_Lin - Test_Data');
Mon_Med_Resid(nIts) = median(tFit_Mon - Test_Data');
Quad_Med_Resid(nIts) = median(tFit_Quad - Test_Data');
end
end
end
end
如果您用第四个循环(nIts)作为for循环运行它。如果你运行它作为一个PARFOR环也不会指出错误:
Error using fit>iFit (line 264) The name 'lower' is not an accessible property for an instance of class 'llsqoptions'.
Error in fit (line 108) [fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
没有人有任何想法如何解决这一问题?我会非常感谢任何建议!
感谢,
本
尝试重新启动MATLAB或打字clear all
,看它是否清除事情你。
你的代码适用于我,但并行工具箱可以是我的经验有点挑剔。
谢谢@information我以为我已经清除了一切,但很明显我没有。我会离开帖子,因为它可能对想要做曲线拟合或使用并行工具箱的人有用。再次感谢。 – Ben
奇怪。你的代码适合我。 – informaton
哦 - 它可以作为parfor? – Ben
是的,作为parfor。我想知道为什么你的曲线拟合工具箱和并行处理工具箱在这里引起冲突。你可以尝试一个“清除所有”的措施。 – informaton