MATLAB: Error encountered when attempting to use Text()

text;

Hi, I'm relatively new to Matlab. I've been trying to annotate some specific points in my graph but keep encountering this error: "Subscript indices must either be real positive integers or logicals.". This error appears even when I used the example code (see below). I noticed that if I start my command window fresh, the example code works fine, but as soon as I load my data, the error appears again both when I plot my own data and when I use the example code. Any idea as to why this is the case? Thanks
x = 0:pi/20:2*pi;
y = sin(x);
figure % new figure window
plot(x,y)
text(pi,0,' \leftarrow sin(\pi)')
Subscript indices must either be real positive integers or logicals.

Best Answer

Looks like he defined an array named text in which case he's aliased the builtin text function. Using a set of subscripts looking like those for the function would, indeed, be trying to use a text string for at least one of those which would raise the error...
>> text=rand(3);
>> text(0,0,'Hello world')
Subscript indices must either be real positive integers or logicals.
>>
Moral: Don't do that! :)
Rename the array to something that doesn't clash with any Matlab-supplied function.
Text, txt, ..., etc., ...