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에서 Array Geometries and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
