I'm trying to create a function and it's not working, I don't know what's wrong with it?

1 Ansicht (letzte 30 Tage)
function gx = g(x)
x1 = find(x <-pi);
gx(x1)=-1;
x2 = find(x>=-pi & x<=pi);
xs = x(x2);
gx(x2)=cos(xs);
x3 = find(x>pi);
gx(x3)=-1;
end
x=-2.*pi;0.01;2.*pi;
gx=g(x)
plot (x,gx)

Antworten (1)

the cyclist
the cyclist am 29 Okt. 2021
You need
x=-2.*pi:0.01:2.*pi;
instead of using semicolons for defining the vector.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by