Bazman
Bazman

Reputation: 2150

Matlab try/catch

for ii = 1:2:2*de.nP            
        G=[one, aux3(:,ii), aux3(:,ii) - aux2(:,ii),aux3(:,ii+1) - aux2(:,ii+1)];

        try
        betasPu(:,(ii+1)/2) =G\yM;
        catch ME
         betasPu(:,(ii+1)/2)=[Inf,Inf,Inf,Inf];
        end 
end

I am using the code above to try and catch instances when the G used in G\yM; is badly conditioned/singular.

I have used the code above but right now the catch does not seem to be triggering despite several badly conditioned/singular matrices being produced.

Upvotes: 3

Views: 2757

Answers (1)

Gunther Struyf
Gunther Struyf

Reputation: 11168

I think badly conditioned calculations doesn't cause errors, only warnings? afaik warnings aren't caught..

There are however some circumventions:

  • You can check lastwarn to detect a warning.
  • You can modify a warning to generate an error as explained here.

Upvotes: 4

Related Questions