Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Create An Array That Contains All the Values of F(x)? Help!

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?

1 Comment

Steven on 19 Sep 2013

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

Steven

Products

No products are associated with this question.

3 Answers

Answer by James Tursa on 19 Sep 2013

y = x;

y(y<1) = 1;

y = y.*x;

0 Comments

James Tursa
Answer by Azzi Abdelmalek on 19 Sep 2013
x=-5:5
y=(x<1).*x+(x>=1).*x.^2

0 Comments

Azzi Abdelmalek
Answer by Jan Simon on 19 Sep 2013

And to be complete:

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

0 Comments

Jan Simon

Contact us