Matlab learning summary
Posted saurywb
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Matlab learning summary相关的知识,希望对你有一定的参考价值。
1.Overload your functions by having variable number of input and output argumernt.Not only can we overload functions also operators.
我们可以通过不同的输入输出来重载函数,当然我们还可以重载运算符。(see varargin,varargout,nargin,nargout)
varargin :
Allows any number of arguments to a function. The variable varargin is a cell array containing the optional arguments to the function. varargin must be declared as the last input argument and collects all the inputs from that point onwards. In the declaration, varargin must be lowercase (i.e., varargin).
允许函数输入任意数量的参数,varargin实际上是一个cell,包含着函数的可选参数。varargin参数必须在参数列表的最右面,在声明时,varargin必须小写!
For example, the function,
例如,函数:
function myplot(x,varargin)
plot(x,varargin:)
collects all the inputs starting with the second input into the variable "varargin". MYPLOT uses the comma-separated list syntax varargin: to pass the optional parameters to plot.
这个函数把从第二个输入的参数全部收集进变量"varargin"
The call,
myplot(sin(0:.1:1),‘color‘,[.5 .7 .3],‘linestyle‘,‘:‘)
results in varargin being a 1-by-4 cell array containing the
values ‘color‘, [.5 .7 .3], ‘linestyle‘, and ‘:‘.
varargout:ariable length output argument list.
Allows any number of output arguments from a function. The variable varargout is a cell array containing the optional output arguments from the function. varargout must be declared as the last output argument and must contain all the outputs after that point onwards. In the declaration, varargout must be lowercase (i.e., varargout).
允许函数任意数量的输出,varargout和varargin的数据类型一样,是一个cell,包含了函数的可选的任意输出,同样varargout也必须是在输出的左后一个参数,在声明时,varargout必须小写!
varargout is not initialized when the function is invoked. You must create it before your function returns. Use NARGOUT to determine the number of outputs to produce.
varargout直至函数被调用时才被初始化,你必须在你的函数返回前创造他,使用NARGOUT来决定要产生的输出(总)的数目。
For example, the function,
例:
function [s,varargout] = mysize(x)
nout = max(nargout,1)-1;
s = size(x);
for i=1:nout, varargout(i) = s(i);%提前创造varargin(remember varargout is a cell)
end
returns the size vector and optionally individual sizes. So,
[s,rows,cols] = mysize(rand(4,5));
returns s = [4 5], rows = 4, cols = 5.
2.Visualizing matrices 的几个函数
a.colormap b.surf c.contour d.colorbar e.imagesc
(all thiese are built-inn functions)
3.计算程序运行的时间;
tic ....toc1...toc2...此外还有for more complicated situation >>profile on;>>profile viewer
以上是关于Matlab learning summary的主要内容,如果未能解决你的问题,请参考以下文章
Coursera machine learning 第二周 quiz 答案 Octave/Matlab Tutorial
Deep Learning学习 之 CNN代码解析(MATLAB)
基于MATLAB的迭代学习控制(Iterative Learning Control,ILC)算法的仿真与分析
機器學習基石(Machine Learning Foundations) 机器学习基石 作业四 Q13-20 MATLAB实现