MATLAB: How to skip error and continue to execute the code

skip error

I have a for loop, but when I faced the following error, my script will stop executing. How can I do to skip the error and continue to execute the code?
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in ReadinData (line 160)
NonData=[Weight;Height;Age];
I have loop like this
for i = 1:100
How can I record i when the error happen, so I can check after the problem execution.

Best Answer

Hi Jason,
one way would be to catch the error:
for i=1:100
try
NonData=[Weight;Height;Age];
% do something with your NonData
catch
fprintf('Inconsistent data in iteration %s, skipped.\n', i);
end
end
Titus