依然贴一个链接
http://3y.uu456.com/bp-17e6f009ba1aa8114431d93c-2.html
a=pi+sqrt(5) %一个数值
sa=sym('pi+sqrt(5)') %生成一个表达式
Ca=class(a)
Csa=class(sa)
vpa(sa-a) %这里可以说是运算,数值化。
当需要学习Matlab中一个函数的用法时,第一步就是help。
>> help feval;
FEVAL Execute the specified function.
FEVAL(F,x1,...,xn) evaluates the function specified by a function
handle or function name, F, at the given arguments, x1,...,xn.
FEVAL is usually used inside functions which take function
handles or function strings as arguments.
[y1,..,yn] = FEVAL(F,x1,...,xn) F是需要使用函数的函数名,或者句柄;xi是函数的参数,yi是函数的返回值
举例:
假设需要调用的函数foo定义如下:
function x=foo(a,b)
x=a*b;
若在main函数中用feval调用foo,可以有以下几种方式
1. result=feval('foo',3,15);
2. result=feval(@foo,3,16); %这里@foo即句柄
3. 若调用的函数要作为main的参数,则
function result=main(f)
result=feval(f,3,10);
然后调用main时将'foo'传入即可
>>main('foo');
matlab中repmat函数的用法
B = repmat(A,m,n)
B = repmat(A,[m n])
B = repmat(A,[m n p...])
这是一个处理大矩阵且内容有重复时使用,其功能是以A的内容堆叠在(MxN)的矩阵B中,B矩阵的大小由MxN及A矩阵的内容决定,如果A是一个3x4x5的矩阵,有B = repmat(A,2,3)则最后的矩阵是6x12x5
例如:
>>B=repmat( [1 2;3 4],2,3)
B =
1 2 1 2 1 2
3 4 3 4 3 4
1 2 1 2 1 2
3 4 3 4 3 4
其结果变为4X6。A也可以置放文字串,如:
>>C=repmat(' Long live the king!', 2,2)
C =
Long live the king! Long live the king!
Long live the king! Long live the king!
也可置放其他的:
>> D=repmat(NaN,2,5)
D =
NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN
matlab isscalar判断是否是一个标量
prod([1:5])
返回120
prod([2 4 6 8])
返回 384
prod([3 4; 4 5]
返回每列元素的乘积 12 , 20
函数名称: isnumeric 函数功能: 判断输入参数是否是数字类型(包括浮点型和整型) 语法格式: tf = isnumeric(A) 返回1(true)如果A是数字类型的, 返回0(false)如果A不是数字类型的.类型的。 相关函数:isa、islogical 应用举例 >> char_arr = 'Hello'; >> isnumeric(char_arr) ans = 0 >> fp_arr = [1.0, 2.1, 3.2]; >> isnumeric(fp_arr) ans = 1 >> integer_arr = int32([1 2 3]); >> isnumeric(integer_arr) ans = 1 >> bool_ver = ispc; >> isnumeric(bool_ver) ans = 0
>>C{1,1} = pi; % double C{1,2} = 1; % double C{1,3} = ispc; % logical C{1,4} = magic(3) % double array C = [3.1416] [1] [1] [3x3 double] >>for k = 1:4 x(k) = islogical(C{1,k}); end x x = 0 0 1 0 示例二: >> A = [true 1 false 0]; >> islogical(A) ans = 0 >> A = [true true false false]; >> islogical(A) ans = 1