Array indices must be positive integers or logical values.
Afficher commentaires plus anciens
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;
Réponse acceptée
Plus de réponses (1)
Steven Lord
le 5 Nov 2022
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).
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
