From: maxwell10 on
I am using 'loop' in order to fit exp to thousands vectors.
Few vector has problematic curve to fit and the loop stop and return. The following massage is apear:

??? Error using ==> parallel_function at 587
Error in ==> fit at 437
Inf computed by model function.

How can i force the function continue calculate and not go out the loop after problematic vector.

This is the loop:
% I is a matrix [100,000;50]
parfor k=1:size(I,1) % can also be 'for' loop
m=I(k,:); % Extract a vector of the matrix
x=0:(length(m)-1); % Form new vector from 0 to ...
f=fittype('a+b*exp(c*x)','independent','x');
[cfun,gof,output]=fit(x',m',f,'startpoint',[3 7-0.1]);
y(k)=cfun.c; % Extract the result
end

I wish to fix y(k)=NaN in case of problematic vector.
From: dpb on
maxwell10 wrote:
> I am using 'loop' in order to fit exp to thousands vectors.
> Few vector has problematic curve to fit and the loop stop and return.
> The following massage is apear:
>
> ??? Error using ==> parallel_function at 587
> Error in ==> fit at 437
> Inf computed by model function.
>
> How can i force the function continue calculate and not go out the
> loop after problematic vector....

Put the call in a try...catch block and hope it will catch the exception...

doc catch

and read the "The try-catch Statement" in documentation...

--
From: maxwell10 on
I am looking for another solution.
Can I force the Matlab to continue the loop even in case of error?
Can I somehow extract a flag from the 'Fit' function that indicate if it managed to fit or failed to?
From: dpb on
maxwell10 wrote:
> I am looking for another solution.
> Can I force the Matlab to continue the loop even in case of error?
> Can I somehow extract a flag from the 'Fit' function that indicate if it managed to fit or failed to?

Doubt it; the error you're running into is numeric owing to argument to
exceeding range of exp() function. Don't recall that ML has any other
provisions for floating point exception handling which is what you're
asking for although newer versions than I have may have some additional
features; all I can suggest is read documentation looking for that kind
of buzz word/phrase/subject.

--
From: Steven Lord on

"maxwell10" <maxwellphy(a)hotmail.com> wrote in message
news:1450865874.213500.1274695932537.JavaMail.root(a)gallium.mathforum.org...
>I am looking for another solution.
> Can I force the Matlab to continue the loop even in case of error?

Yes, by using a TRY/CATCH block as dpb suggested.

> Can I somehow extract a flag from the 'Fit' function that indicate if it
> managed to fit or failed to?

Yes; that flag is known as an error that can be detected via TRY and CATCH.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com