Possible matlab bug with text() function?

16 ビュー (過去 30 日間)
Azhar Ali
Azhar Ali 2019 年 9 月 18 日
コメント済み: Steven Lord 2024 年 6 月 9 日
I'm having issues with the text function. I am copying your example from the documentation, and I get the following error:
"Subscript indices must either be real positive integers or logicals."
Here is the example:
x = 0:pi/20:2*pi;
y = sin(x);
plot(x,y)
text(pi,0,'\leftarrow sin(\pi)')
I am using Matlab 2013a. Very simple example, not sure why I can't replicate the documentation example. Thank in advance!
  2 件のコメント
Kevin Phung
Kevin Phung 2019 年 9 月 18 日
where is it throwing the error? It runs for me
Azhar Ali
Azhar Ali 2019 年 9 月 18 日
Error is thrown for text function despite no other variables in workspace. Reboot of computer and Matlab resolved issue.

サインインしてコメントする。

採用された回答

madhan ravi
madhan ravi 2019 年 9 月 18 日
編集済み: madhan ravi 2019 年 9 月 18 日
When you name variable as the same name as the function this happens.
clear text plot sin % not sure which function you’re shadowing , but it definitely is a reason

その他の回答 (2 件)

Azhar Ali
Azhar Ali 2019 年 9 月 18 日
I had no variables in my workplace (clear; clc; close all) and I still had the error. I rebooted computer and Matlab and it resolved the issue. Weird. Still don't know why I got the error, but problem is fixed. Thanks all.
  1 件のコメント
Steven Lord
Steven Lord 2019 年 9 月 18 日
If this recurs, set an error breakpoint and run your code. When you receive the error, check if you are in a function named text.m (which would be shadowing the built-in text function.) If you are not, post the full text of the error message (all the text displayed in red, not just the "Subscript indices must either be real positive integers or logicals." part) and it may provide the information needed to determine the cause.

サインインしてコメントする。


Lola Gadea
Lola Gadea 2024 年 6 月 9 日
I have the same problem with the 2023a version:
x = 0:pi/20:2*pi;
y = sin(x);
plot(x,y)
text(pi,0,'\leftarrow sin(\pi)')
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in example_labels5 (line 4)
text(pi,0,'\leftarrow sin(\pi)')
  1 件のコメント
Steven Lord
Steven Lord 2024 年 6 月 9 日
What does this command show?
which -all text
built-in (/MATLAB/toolbox/matlab/graphics/primitive/text)
I'm betting it will show something that looks like the following instead of the text above (note the first line.)
text = 42;
which -all text
text is a variable. built-in (/MATLAB/toolbox/matlab/graphics/primitive/text) % Shadowed

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2013a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by