MATLAB Programming Tips - The MathWorks - #51

/ 66


catalogue search
P. 51
P. 52
P. 53
P. 54
P. 55
P. 56
P. 57
P. 58
P. 59
P. 60
P. 61
P. 62
P. 63
P. 64
P. 65
P. 66


See other catalogues for The MathWorks

Text version of the page
Program Control
try
X = A* B catch
errmsg = lasterr;
if(strfind(errmsg, 'Inner matrix dimensions')) disp('** Wrong dimensions for matrix multiply')
end
For more information: See "The try-catch Statement" in the MATLAB Programming Fundamentals documentation.
Nested try-catch Blocks
You can also nest try-catch blocks, as shown here. You can use this to attempt to recover from an error caught in the first try section:
try
statement1 % Try to execute statement1
catch try
statement2 % Attempt to recover from error
catch
disp 'Operation failed' % Handle the error
end
end
Forcing an Early Return from a Function
To force an early return from a function, place a return statement in the function at the point where you want to exit. For example,
if <done> return
end
1-43

pageCatalog pdf di En 2012-06-22-01