[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
nargin
函数输入参数数目
语法
nargin
nargin(fun)
说明
1、nargin 针对当前正在执行的函数,返回函数调用中给定函数输入参数的数目。该语法仅可在函数体内使用。
示例
在名为 addme.m 的文件中创建最多可接受两个输入的函数。在函数主体中使用 nargin 确定输入数目。
function c = addme(a,b) switch nargin case 2 c = a + b; case 1 c = a + a;
otherwise c = 0; end end
2、nargin(fun) 返回 fun 函数定义中出现的输入参数的数目。如果该函数定义中包含 varargin,那么 nargin
返回输入数目的负数。例如,如果 myFun 函数声明输入 a、b 和 varargin,那么 nargin(‘myFun’) 返回 -3。
确定一个函数可接受多少个输入。
上一个示例中创建的 addme 函数在声明语句中包含两个输入(a 和 b)。以字符向量的形式定义函数名称,并使用它作为 nargin 的输入
确定使用 varargin 的函数可接受多少个输入。
在名为 mynewplot.m 的文件中创建一个函数,该函数接受数值输入 x 和 y,并使用 varargin 返回任意数目的其他绘图输入。
function mynewplot(x,y,varargin) figure plot(x,y,varargin{:}) title('My New
Plot') end
查询 newplot 可以接受多少个输入。
fx = ‘mynewplot’;
nargin(fx)
ans = -3
负号表示第三个输入是 varargin。mynewplot 函数可接受不定数目的附加输入参数。
varargin把第三个参数就设置为无效了,第四个也没什么用处了。
仅仅记录学习。