MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Steven
on 19 Sep 2013

I have a function f(x) that equals x if x < 1 and x^2 elsewhere.

How would I go about putting all the values of f(x) into another array, named y, for example?

*No products are associated with this question.*

Answer by Jan Simon
on 19 Sep 2013

Accepted answer

And to be complete:

y = x.^2; y(x < 1) = x(x < 1);

## 1 Comment

## Steven (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/87625#comment_169798

If this helps x = linspace(-1,2,100).