Array indices must be positive integers or logical values.
显示 更早的评论
clc;
x = -6; %input value for following expression
if x < -5
f(x) = 0;
elseif -5 <= x && x < 5;
f(x) = 2 * x^1/2 + exp(x/4);
elseif 5 <= x && x <= 20;
f(x) = log((x^2));
else
f(x) = 0;
end
f(x)
how can i get my code to work for values -infinity to 0 for this expression? i keep getting this error code
Array indices must be positive integers or logical values.
Error in Homework_two (line 11)
f(x) = 0;
采纳的回答
更多回答(1 个)
Steven Lord
2022-11-5
x = -6; %input value for following expression
if x < -5
f(x) = 0;
There's no such thing as element -6 of an array in MATLAB. If you want f to be one element long and you want its value to depend on x, assign to f not f(x).
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
