Error encountered when attempting to use Text()
2 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
dpb
on 25 Jan 2015
Edited: dpb
on 25 Jan 2015
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., ...
More Answers (1)
Image Analyst
on 25 Jan 2015
It works fine for me - no errors. And I can run it over and over again with no errors. Perhaps you used Text() (like you said in your subject line) instead of text(). MATLAB is case sensitive.
Come back with the complete code if the FAQ does not answer your question: http://matlab.wikia.com/wiki/FAQ#How_do_I_fix_the_error_.22Subscript_indices_must_either_be_real_positive_integers_or_logicals..22.3F
0 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!