so i've tried to plot this funtion multiple times using every trick i can come up with and the loop still only goes through the first ifelse statement in the function file. here is a copy of my function file:

Code:

function y=f(x)
if x<=-1;
y=15;
elseif -1<=x<=1;
y=-5.*x+10;
elseif 1<=x<=3;
y=-10.*x.^2+35.*x-20;
elseif 3<=x<=4;
y=-5.*x+10;
elseif 4<=x<=5 ;
y=-10;
end
end

using this file I try to plot in my main file which is:

Code:

delete g228x07.txt; diary g228x07.txt
clear; clc; close all; echo on
% Gilat 228/7
x=[-2:.01:5];
n=length(x);
for i=1:n;
y(i)=f(x(i));
end
plot(x,y);
grid on
echo off; diary off

the first three lines are just a reference header and do not impact the problem. I don't know if the loop fails in the for loop or in the ifelse on the function file.