Matlab基础学习(1)

  最近要用数学建模,打算好好学一下matlab.作为一个数学工具,matlab不可谓不强大,但是学好不容易。

1. 数据类型

 

这是数据结构的框架,数值类和字符串类在其他语言都很常见, 函数句柄区别不同的函数,cell和struct在很多语言也都有,用到再说,逻辑类主要用来判断(一个0-1矩阵或者0-1向量,很有用!)

 不同数据类型 交叉使用,一定要进行数据类型转换.具体查看help-MATLAB-Functions-Programming and Data Types-Data Types,help-MATLAB-Functions-Programming and Data Types-Data Type Conversion.

help-MATLAB-Functions-Programming and Data Types 是一个很重要的函数帮助文档。

包含了和数据类型相关的所有函数。 重点关注:Data Type,Data Type Conversion,Operators and Special Characters,Strings,Bit-Wise Operators,Logical Operations.

 

2. 符号说明。

算术运算符:

注意 .opr 和 opr的区别:一个是元素对元素;一个是矩阵对矩阵

 

关系运算符:

和C语言基本相同,除了不等号~=

 

逻辑运算:( 重要)

与:& and()        %&&只能用于标量

或:| or()           %||只能用于标量

非:~ not()

异或:xor()

all()=and( , , ,..., )所有条件都要成立

any()=or( , , ,..., ) 至少一个条件成立

 

 特殊运算符:

:     Create vectors, subscript arrays, specify for-loop iterations

()    Pass function arguments, prioritize operators

;      Separate columns of array, suppress output from current command

,      Separate rows of array, separate function input/output arguments, separate commands

[]    Construct array, concatenate elements, specify multiple outputs from function   

''     Construct character array     %string 

{}   Construct cell array, index into cell array                  %cell

.      Insert decimal point, define structure field, reference methods of object                     %struct,object

%    Insert comment line into code        % 注释

@    Construct function handle, reference class directory       %函数句柄

 

3.is_ 

help-MATLAB-Functions-Mathematics-Arrays and Matrices-Basic Information 可以找到is_类的函数,判断向量、矩阵的是否符合一个要求,并返回0/1

 

4.矩阵的基本操作

A是一个矩阵

A(:,j)

is the jth column of A.

A(i,:)

is the ith row of A.

A(:,:)

is the equivalent two-dimensional array. For matrices this is the same as A.

A(j:k)

is A(j), A(j+1),...,A(k).

A(:,j:k)

is A(:,j), A(:,j+1),...,A(:,k).

A(:,:,k)

is the kth page of three-dimensional array A.

A(i,j,k,:)

is a vector in four-dimensional array A. The vector includes A(i,j,k,1), A(i,j,k,2), A(i,j,k,3), and so on.

A(:)

is all the elements of A, regarded as a single column. On the left side of an assignment statement, A(:) fills A, preserving its shape from before. In this case, the right side must contain the same number of elements as A.

 删除只需要=[]即可,例如:A(:,j)=[].

 

矩阵有线性索引和行、列索引两种:

A=[1 2 3;4 5 6]

线性索引:

1  4 2 5 3 6

行列索引会返回行数和列数.

A(2)

ans= 4

 

A[2][1]

ans=4

 

转换使用:

[I J]=ind2sub(size(A),ind)

ind=sub2ind(size(A),I,J)  %ind,I,J都是向量

posted @ 2015-12-01 15:14  霖霖柒  阅读(57)  评论(0)    收藏  举报