用MATLAB怎么编写分段函数程序,题目是x[n]=n+1 0<=n<=3;x[n]=8-n 4<=n<=7; x[n]=0 n=other;

急需知道

第1个回答  2010-05-21
n= %输入的正整数(matlab中角标必须是正整数)
for i=1:n
if i<=3
x[i]=i-1;
else if i<=7
x[i]=8-i;
else
x[i]=0;
end
end
end本回答被网友采纳
第2个回答  2010-05-25
例如:
x=-5:10;
>> y=(x+1).*(x>=0&x<=3)+(8-x).*(x>=4&x<=7)

y =

0 0 0 0 0 1 2 3 4 4 3 2 1 0 0 0
相似回答