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

matlab system,fullfile, feval,contourc

2014-01-08 20:05 381 查看
1.matlab system

在Matlab里可以通过system这个命令调出dos命令,比如:执行语句system('mkdir step1')就可以在当前目录下建立名为step1的文件夹!在实际编程中,可以结合函数exist使用。比如:

ifexist('Step1') == 0

system('mkdirStep1');

end

即:先判断当前目录下是否以存在名为Step1的子目录(文件夹),如果不存在,则建立。

概述:执行操作系统命令并返回输出

status= system(command)

[status,cmdout]=system(command) example

[status,cmdout]=system(command,'-echo')

examples:

windows系统下

(1):command = 'cd';

[status,cmdout] = system(command)

status = 0;cmdout =C:\matlab\myfiles;

返回的是当前的文件夹目录。

(2):[~,hostname] = system('hostname');

hostname = strtrim(hostname);

switch hostname

case 'hxm-pc'

[~,uname]=system('whoami');uname=strtrim(uname);%获取主机名和使用者名字

在我这台电脑上hostname:hxm-pc;unmane:hxm-pc/administrater



2.matlab params

Params is a read-only property of the
ProbDistParametricclass. Params is an array of values specifying the values of theparameters of a distribution represented by a ProbDistParametric object. Paramshasa length of NumParams.

是ProbDistParametric的只读属性即成员,是一个值的数组。

3.matlab fullfile

f = fullfile(filepart1,...,filepartN)buildsa full file specification, f, from the foldersand file names specified.fullfile inserts platform-dependentfile separators where necessary, and doesnot add a trailing fileseparator. The
output of fullfile isconceptuallyequivalent to

f = [filepart1 filesep filepart2 filesep... filesep filepartN]

从每个部分中建立特定的文件名称。

example:

f =fullfile('myfolder','mysubfolder','myfile.m')

f =

myfolder\mysubfolder\myfile.m

4.matlab feval

FEVALExecute 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 takefunction

handles or function strings as arguments.

[y1,..,yn] = FEVAL(F,x1,...,xn)

F是需要使用函数的函数名,或者句柄;xi是函数的参数,yi是函数的返回值

example :

假设需要调用的函数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');



5.matlab reshape

B =reshape(A,m,n)

B =reshape(A,m,n,p,...)

B =reshape(A,[m n p ...])

B =reshape(A,...,[],...)

B =reshape(A,siz)



B =reshape(A,m,n) returns the m-by-n matrix B whose elements are taken column-wisefrom A. An error results if A does not have m*n elements.

作用就是将A以一列一列的方式抽取元素组成m*n的矩阵B

example:

A =

1 4 7 10

2 5 8 11

3 6 9 12



B =reshape(A,2,6)



B =

1 3 5 7 9 11

2 4 6 8 10 12

B =reshape(A,2,[])



B =

1 3 5 7 9 11

2 4 6 8 10 12

6.matlab contourc

contour是等高线绘制函数

contour(Z)根据矩阵Z画出等高线,Z是以x,y为平面的高度。Z必须是一个至少二维的矩阵。

等高线的数量和水平线的值将根据Z值的最小值和最大值自动选择。

x,y轴的范围是[1:n]和[1:m],[m,n]=size(Z)

contour(Z,n)用n条水平线来绘制Z的等高线。

contour(Z,v)是以向量v中的数据来绘制矩阵Z的等高线。

等高水平线的个数等于向量v的长度。如果想画一条单个等高线,使用contour(Z,[i i]).

contour(X,Y,Z),contour(X,Y,Z,n),contour(X,Y,Z,v)绘制Z的等高线。X,Y限制在x,y轴上的范围。如果X,Y是矩阵,它们必须跟Z是同型矩阵,此时它们描述了一个表面,因此应当用surf函数定义一下。

x=1:1:6;

y=1:1:14;

[xx,yy]=meshgrid(y,x);

z=[2.442.78 3.46 4.55 3.43 2.72 2.46 2.46 2.72 3.43 4.55 3.46 2.78 2.44;

3.004.42 5.96 6.06 6.00 4.65 3.82 3.82 4.65 6.06 6.00 5.96 4.42 3.00;

2.312.54 3.87 6.25 3.89 2.51 2.24 2.24 2.51 3.89 6.24 3.87 2.54 2.30;

2.322.55 3.88 6.25 3.89 2.51 2.24 2.24 2.51 3.89 6.24 3.87 2.54 2.29;

3.074.46 5.97 6.05 6.00 4.65 3.82 3.82 4.66 6.06 6.00 5.94 4.37 2.93;

2.392.75 3.43 4.52 3.42 2.71 2.45 2.46 2.72 3.45 4.59 3.52 2.84 2.43;];

contour(xx,yy,z,15);



The contour matrix that contourc returns isbasically a bunch of vertices that define the contour lines. Each vertex
is an(x,y) pair and they are stored as columns in the contour matrix:
x1 x2 x3 ...
y1 y2 y3 ...
Except, there are also some columns in the matrix that holdinformation about how many vertices the contour line has and level (e.g.
0.8)of the contour. So the contour matrix might actually look something like this:

0.8 x1 x2 x3...
386 y1 y2 y3
contourc的返回值。前两个保存的是描述等高线的信息,高度为0.8的等高线,后面386列等高线的坐标。
Thefirst column says that the next 386 columns are going to contain coordinates ofa line at the contour level 0.8
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: