Clc, clear, close all.
x =-5:. 1:5;
y(x & gt; = 1) = 3.* x(x & gt; = 1).^2+ 1;
y(x & gt; - 1 & amp; & ampx & lt 1) = 0;
y(x & lt; =- 1)=-x(x & lt; =- 1).^3+2;
Drawing (x, y)
Extended data:
Matters needing attention
grammar
If expression
statement
end
describe
MATLAB calculates the expression, and if it produces a logical true or non-zero result, it executes one or more MATLAB command statements.
When there are nested ifs, each if must match a corresponding ending.
When using else if or else nesting in an if statement, the general format is as follows:
If expression 1
Statement 1
Elseif expression 2
Statement 2
other
Statement 3
end