Sunday, May 18, 2008

Error handling in MATLAB

Most Cpp users know it guess but let me tell you what I wanted to..
MATLAB has similar error handling functions like throw and catch. If you think that in some part of the code is prone to exceptions say.. you are uing kmeans clustering function and as you knowit is some times unstable because of the dependency on the initial random guess of the means. If it says some thing like "initial iteration produced cluster of zero size" calling it one more time helps (if it is your bad day it again shows you the same error and calling it onemore time porbably brings you out of trouble ), This calling the function second time if it resulted in exception can be done like this
try
[idx cen]=kmeans(data,k);
catch
try
[idx cen]-kmeans(data,k);
catch
[idx cen]-kmeans(data,k);
end
end
You can put some more nested try catches if you want your code to be much more reliable
Thanky you

have a happy time blogging

RAMA


No comments: