为了账号安全,请及时绑定邮箱和手机立即绑定

例如ones函数的源代码:看不太懂,求助!

例如ones函数的源代码:看不太懂,求助!

幕布斯6054654 2022-08-04 11:07:48
function [varargout] = ones(varargin)%ONES Ones array.% ONES(N) is an N-by-N matrix of ones.%% ONES(M,N) or ONES([M,N]) is an M-by-N matrix of ones.%% ONES(M,N,P,...) or ONES([M N P ...]) is an M-by-N-by-P-by-... array of% ones.%% ONES(SIZE(A)) is the same size as A and all ones.%% ONES with no arguments is the scalar 1.%% ONES(M,N,...,CLASSNAME) or ONES([M,N,...],CLASSNAME) is an M-by-N-by-...% array of ones of class CLASSNAME.%% Example:% x = ones(2,3,'int8');%% See also EYE, ZEROS.% Copyright 1984-2003 The MathWorks, Inc.% $Revision: 5.10.4.3 $ $Date: 2004/04/16 22:05:14 $% Built-in function.if nargout == 0builtin('ones', varargin{:});else[varargout{1:nargout}] = builtin('ones', varargin{:});end
查看完整描述

1 回答

?
慕婉清6462132

TA贡献1804条经验 获得超2个赞

if nargout == 0 % nargout代表函数实际输出参数的个数。
% 如果在命令行直接调用ones(...),nargout=0
% 如果给一个变量赋值,比如a=ones(...),nargout=1
% 如果给若干变量赋值,如[a, b, ...]=ones(...),有几个变量,nargout就是几。
builtin('ones', varargin{:}); % 如果无输出参数,调用内建的ones函数
else
[varargout{1:nargout}] = builtin('ones', varargin{:}); % 否则,同样调用内建ones函数,但要给输出变量赋值返回的结果。varargout表示所有输出参数组成的队列。
end

查看完整回答
反对 回复 2022-08-08
  • 1 回答
  • 0 关注
  • 260 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号