Imag, real function error
显示 更早的评论
when I try to use the imag or real functions I get an error saying 'Subscript indices must either be real positive integers or logicals.' I don't get this when I use the isreal or abs functions. Why is this?
3 个评论
James Tursa
2017-9-12
Please post your code that generates this error.
Sean Pitre
2017-9-12
编辑:Walter Roberson
2017-9-12
James Tursa
2017-9-12
Try clearing all variables first, and then re-try your code to confirm that it is a variable naming issue or not.
回答(2 个)
James Tursa
2017-9-12
编辑:James Tursa
2017-9-12
0 个投票
It could be that you have inadvertently created variables with the name "real" or "imag" that are shadowing the functions real and/or imag.
Star Strider
2017-9-12
编辑:Star Strider
2017-9-12
My guess is that you used ‘imag’ and ‘real’ as variables somewhere earlier in your code. The solution is to find those variables and rename them. (The builtin (link) function can shed light on this.)
Example —
imag = 42;
x = 1 + 2*j;
A1 = builtin('imag', x)
A2 = imag(x)
yields:
A1 =
2.0000e+000
For ‘A2’:
Subscript indices must either be real positive integers or logicals.
Error in FileName (line #####)
A2 = imag(x)
3 个评论
Sean Pitre
2017-9-12
James Tursa
2017-9-12
What does this show?
which real
which imag
Star Strider
2017-9-12
The which function can be helpful.
Note all the results from:
which real -all
If the first result is:
real is a variable.
you’ve found the problem.
类别
在 帮助中心 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!