MATLAB: Error showing that variable ‘x’ might be a non scalar operator. Why is it so

non scalar operator

x = 0:0.01:1;
if x < 0.5
y = x^2;
else
y = x^2 -1;
plot(x,y)
end

Best Answer

x = 0:0.01:1;
y(x<.5)=x(x<.5).^2;
y(x>=.5)=x(x>=.5).^2-1;
plot(x,y);