您的位置:首页 > 编程语言 > MATLAB

MATLAB中函数模式和命令模式的区别

2012-11-05 14:51 1136 查看
FUNCTION FORMAT

A command in this format consists of the function name followed by

one or more arguments separated by commas and enclosed in parentheses

函数格式的命令由函数名和紧随其后的一个或者多个参数组成;这些参数用,隔开

并放在()里面。

.

functionname(arg1, arg2, ..., argn)

You may assign the output of the function to one or more output values

separated by commas and enclosed in square brackets ([]).

你也可以指定函数的输出为一个或者多个输出变量,用,隔开

并放在()里面。

[out1, out2, ..., outn] = functionname(arg1, arg2, ..., argn)

For example,

copyfile(srcfile, '..\mytests', 'writable')

[x1, x2, x3, x4] = deal(A{:})

Arguments are passed to the function by value. See the examples below,

under ARGUMENT PASSING. 参数是被传送到函数的值

COMMAND FORMAT

A command in this format consists of the function name followed by

one or more arguments separated by spaces.

命令模式命令由函数名和紧随其后的一个或者多个参数组成,这些参数用空格隔开。

functionname arg1 arg2 ... argn

Unlike the function format, you may not assign the output of the function

to a variable. Attempting to do so generates an error.

有别于函数模式,你不能把函数的输出指向变量。如果这样做会产生错误。

For example

save mydata.mat x y z

import java.awt.Button java.lang.String

Arguments are treated as string literals. See the examples below,

under ARGUMENT PASSING.

这里的参数被当成字符串常量。

ARGUMENT PASSING

In the FUNCTION format, arguments are passed by value.

在函数模式,参数被变量传递。

In the COMMAND format, arguments are treated as string literals.

在命令模式,参数被当做字符串常量。

In the following example,

disp(A) - passes the value of variable A to the disp function

disp A - passes the variable name, 'A'

A = pi;

disp(A) % Function format

3.1416

disp A % Command format

A

In the next example,

strcmp(str1, str2) - compares the strings 'one' and 'one'

strcmp str1 str2 - compares the strings 'str1' and 'str2'

str1 = 'one'; str2 = 'one';

strcmp(str1, str2) % Function format

ans =

1 (equal)

strcmp str1 str2 % Command format

ans =

0 (unequal)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  MATLAB