matlab求教。z=[0:1:2],x=[0:0.5:3],在x《1时y=x+z;1<x《2,y=1+z:2<x《3,y=x+z-1.。求画出y的图形
clear all;
clc;
z=0:1:2;x=0:0.5:3;
[X,Z]=meshgrid(x,z);
[m,n]=size(X);
Y=zeros(m,n);
for i=1:m
for j=1:n
if X(i,j)<=1
Y(i,j)=X(i,j)+Z(i,j);
end
if X(i,j)>1&&X(i,j)<=2
Y(i,j)=1+Z(i,j);
end
if X(i,j)>2&&X(i,j)<=3
Y(i,j)=X(i,j)+Z(i,j)-1;
end
end
end
surf(X,Z,Y);
结果:
本回答由提问者推荐
收起
为你推荐: