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

1 次查看(过去 30 天)
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?

采纳的回答

Jan
Jan 2013-9-19
And to be complete:
y = x.^2;
y(x < 1) = x(x < 1);

更多回答(2 个)

James Tursa
James Tursa 2013-9-19
y = x;
y(y<1) = 1;
y = y.*x;

Azzi Abdelmalek
Azzi Abdelmalek 2013-9-19
x=-5:5
y=(x<1).*x+(x>=1).*x.^2

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by