MatLab---多个输出变量的函数与没有输出变量的函数

1.多个输出变量的函数

function [area,perimeter]=areaperi(length,width)
area=length*width;
perimeter=2*(length+width);
end

命令行窗口:

[a,b]=areaperi(5,2)  //返回值有面积和周长

a =

10

b =

14

>> c=areaperi(5,2) //返回值只需要面积

c =

10

>> [~,d]=areaperi(5,2) //返回值只需要周长

d =

14

2.没有输出变量的函数

function AutcReply()
ch=input('Enter a char:','s');
if ch=='Y'||ch=='y'
disp('positive command received');
end
if ch=='N'||ch=='n'
disp('negative command received');
end
end

posted @ 2022-04-22 16:35  无敌小金刚  阅读(2075)  评论(0)    收藏  举报