Saving the output from a for loop

조회 수: 9 (최근 30일)
Elizabeth Vieira
Elizabeth Vieira 2016년 1월 21일
댓글: Star Strider 2016년 1월 22일
I am using the following script in MatlabR2015a:
CVO = cvpartition(y2,'k',10);
C=zeros(96,1)
for i = 1:CVO.NumTestSets
trIdx = CVO.training(i);
teIdx = CVO.test(i);
mdl = fitcnb(x1(trIdx, :),y2(trIdx, :),'Distribution', 'kernel')
[label, Posterior] = predict(mdl,x1(teIdx, :))
C(teIdx)=Posterior (:,2);
end
[X,Y,T,AUC] = perfcurve(y2,C,'true','NBoot', 1000); % Curva ROC para os dados de teste do crossval
c1=round(C);
CMat=confusionmat(y1,c1);
How can I save in my workspace the model from each iteration?
Many Thanks,
Elizabeth Vieira

채택된 답변

Star Strider
Star Strider 2016년 1월 21일
You can save it as a cell array (note the curly brackets ‘{}’):
mdl{i} = fitcnb(x1(trIdx, :),y2(trIdx, :),'Distribution', 'kernel');
If you want to save the ‘mdl’ cell array after the loop, use the save function to save it to a .mat file. See the documentation for save for details.
  댓글 수: 3
Elizabeth Vieira
Elizabeth Vieira 2016년 1월 22일
Many thanks!
Star Strider
Star Strider 2016년 1월 22일
My pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Naive Bayes에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by