MATLAB: How to resolve index exceeding error while I plot something

index exceeding errorplottitle

Hello all, I'm keep having error when I tried to put title on my plot. The error message said "Index exceeds matrix dimensions." Here's my code, so please let me know why I got this message. Thanks!
figure
title('2')
h = plot(dataCenter(:,1),dataCenter(:,2),'Color','b')

Best Answer

The error message is clear: An indexing operation in this line exceeds the defined array sizes:
h = plot(dataCenter(:,1),dataCenter(:,2),'Color','b')
Either dataCenter has 1 column only, or you have redefined plot by an array and the inputs are interpreted as indices. You can check both by using the debugger. Type this in the command window:
dbstop if error
Now run the code again until it stops at the problem. Now examine, what's going on:
size(dataCenter)
which plot -all