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));

回答(1 个)

Adam Danz
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));
% ^^

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by