Matlab基本操作0

0,格式

clear

>>a=sin(6*pi/180)

 

a =

 

    0.1045

 

>>format long

>>a

 

a =

 

   0.104528463267653

 

>>format short e

>>a

 

a =   e-1

 b=int8(2)+3.5

 

b =

 

    6

   1.0453e-01

al1=int8(6);

>>a2=int16(6);

>>a3=uint32(100);

>>a4=uint64(200);

>>b1=single(3.5);

>>b2=12;

>>c1=true;

>>c3='hello';

>>c4.name='robin';

>>d=@cos

 

d =

 

    @cos

3,sym函数用于创建符号数字、符号变量、符号对象。符号对象的类型是sym

函数功能:在MATLAB中,该符号变量的优点是,使用符号变量运算得到的只是一个解析解,

例如,在符号变量运算过程中pi就用pi表示,而不是具体的近似数值3.143.14159

把一个数值标量或矩阵转换为符号型的对象。这里flag参数的值可以是:'r', 'd', 'e', or 'f'

它指定了对浮点数进行转换时的规则:%willbe removed

a =sym('a', [1 4])

a =

[ a1, a2,a3, a4]

a =sym('x_%d', [1 4])

a =

[ x_1,x_2, x_3, x_4]

A =sym('A',[3 4])

A =

[ A1_1,A1_2, A1_3, A1_4]

[ A2_1,A2_2, A2_3, A2_4]

[ A3_1,A3_2, A3_3, A3_4]

s1=sym(['x^3-4x^2+9*x-10']);

solve(s1);?%whycan not be solved

s1=sym('[x^3-4*x^2=9*x-10]');%thatis right

y=sym('sin(x)+cos(x)');

Or

x=sym('x');

>>y=ain(x)+cos(x);

4vpa(x,n)   %xn位有效数字

5,roots(p);

   solve('')or solve(s)

fzero('x*sin(x)-1',3)%find root near 3

6,元胞数组无所不包

  creat:1 w={A,B;C,D};

        2 w=[{A},{B};...]

7,struct1, how to creat it

         student.name='dassein';

   2,then automatically  we will have students(2),

        student(2).score(1,;)Enter then you ewill get the ans;%struct可以嵌套

    3,it can beinserted:class.name=1;class.student=student  

1,语法(syntax

1,

MATLAB

1.局部变量

2.全局变量

全局变量采用global进行声明,格式为:global变量1变量2。中间采用空格进行分割。

3.永久变量

永久变量只能在函数M文件中进行定义,格式为:persistent变量变量2。中间采用空格进行分割

2,

Format:

functionresult =valuateScore(x)

     n=fix(x/10);

     switch n

     case{9,10}

         display('Excellent')

      case 8

             display('good')

       case{7,6}

                 disp('ok')

       otherwise

                   display('failure')

end

3, t=(0:1000)  %in m file ,if not have ‘;',t=  1,2...  will show on the screen

4,display(int2str(i));%格式转换,显示数值

5,

如果不能确定某段程序代码是否会出错,可以采用try…catch语句。

try

程序代码1

catch

程序代码2

End

6,

a,主函数进行函数调用时,首先查找该函数文件中的子函数,如果有同名的子函数,则调用该子函数。

因此,可以编写同名的子函数实现函数重载。子函数只能被同一文件的主函数或其它子函数调用

b,函数的内部,还可以定义一个或多个函数,称为函数的嵌套。在函数内部定义的函数称为嵌套函数。

MATLAB中,可以进行多层嵌套,一个函数的内部可以嵌套多个函数,这些嵌套函数内部又可以嵌套其它函数。

c,fhandle=@(arglist)expr %handle as the anonymous function

创建函数句柄使用@或者srt2func命令

7

  functionName();% no output

     [ , ,]=functionName()

      edit% establish new .m

2,基本的预置知识

1... change the line,when the statementis too long;

when thedata of one line is too long :

  1,shift +enter;

>>B=[1 2 3

   4 5 6

   7 88 9]

 

B =

 

     1    2     3

     4    5     6

     7   88     9

  2,B=[1 2 3 ...

       4 5 6 ...

      7 8 9](notice that we should have a spacebetween 3&.)

 

>>D=[1 2 3 ...

4 5 6 ...

7 8 9]

 

D =

 

     1    2     3     4    5     6     7    8     9

2,

@    for the handle

3,

t=linspace(0:0.1:1);

Notenough input arguments.

 

Error inlinspace (line 19)

    n = floor(double(n));

t=linspace(0,0.1,1);%that is the right expression

4,

fix<=>(parameter=0)  round 

5,

const,variable length <=19

file name<=8;        

6,

eps,NaN,inf


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值