Why am I getting "Array indices must be positive integers or logical values"?

1 回表示 (過去 30 日間)
Erik Philip Mcauley
Erik Philip Mcauley 2019 年 12 月 9 日
編集済み: Adam Danz 2019 年 12 月 11 日
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 Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by