Why am I getting "Array indices must be positive integers or logical values"?
1 次查看(过去 30 天)
显示 更早的评论
I'm currently trying to plot a function from x=0 to 1 and the function "var" keeps coming up with the error code "Array indices must be positive integers or logical values". Any suggestions? Thank you
a=1;
n=1;
x=0:0.01:1;
psi=(2/a).^0.5.*sin((n*pi*x)/a);
N=(10.816).^0.5;
var=N(x.^(0.862)-x.^(2.862));
0 个评论
回答(1 个)
Adam Danz
2019-12-9
编辑:Adam Danz
2019-12-10
This line below implies that you're trying to index values from an array N where the index values must be positive integers or logicals.
N(x.^(0.862)-x.^(2.862))
Clearly the "indices" do not meet those requirements.
My guess is that the intention is to multiply N by those values.
var = N .* (x.^(0.862)-x.^(2.862));
% ^^
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!