补充实现一个内含子函数的M函数绘图文件。 function Hr=exm060301(flag) %exm060301.m Demo for handles of primary functions and subfunctions % flag use 'line' or 'circle' % Hr t=(0:50)/50*2*pi; x=sin(t); y=cos(t); _______________; % ______________; end function cirline(wd,x,y,t) %cirline(wd,x,y,t) % wd use 'line' or 'circle' % t % x % y switch wd case 'line' plot(t,x,'b',t,y,'r','LineWidth',2) case 'circle' plot(x,y,'-g','LineWidth',8), axis square off otherwise error('输入宗量只能取''line''或''circle''!') end shg end
时间: 2024-03-22 18:37:37 浏览: 11
下面是补充实现一个内含子函数的M函数绘图文件exm060301.m:
```
function Hr = exm060301(flag)
% exm060301.m Demo for handles of primary functions and subfunctions
% flag use 'line' or 'circle'
% Hr handle for graphics object
% Primary function
t = (0:50)/50*2*pi;
x = sin(t);
y = cos(t);
if strcmp(flag, 'line')
Hr = cirline('line', x, y, t);
elseif strcmp(flag, 'circle')
Hr = cirline('circle', x, y, t);
else
error('输入宗量只能取''line''或''circle''!');
end
% Subfunction
function Hr = cirline(wd, x, y, t)
% cirline(wd,x,y,t)
% wd use 'line' or 'circle'
% t
% x
% y
switch wd
case 'line'
Hr = plot(t, x, 'b', t, y, 'r', 'LineWidth', 2);
case 'circle'
Hr = plot(x, y, '-g', 'LineWidth', 8);
axis square off;
otherwise
error('输入宗量只能取''line''或''circle''!');
end
shg;
end
end
```
该函数包含一个主函数和一个内含的子函数。主函数根据输入的flag参数选择是绘制线条还是绘制圆形,并调用子函数cirline来完成图形的绘制。子函数根据输入的wd参数选择是绘制线条还是圆形,并返回绘制的图形句柄Hr。
调用该函数时,可以输入'line'或'circle'作为参数flag,来绘制不同的图形。例如,输入exm060301('line')将绘制一个包含两条线段的图形,输入exm060301('circle')将绘制一个圆形。
该函数还返回一个图形对象的句柄Hr,可以用于后续的操作。