MATLAB上机

来源:互联网 发布:大连软件职业学院多大 编辑:程序博客网 时间:2024/06/06 05:29
>> A=[1,2;3,4]


A =


     1     2
     3     4


>> B=[5,6;7,8]


B =


     5     6
     7     8


>> C=A*B


C =


    19    22
    43    50


>> //
 //
|
Error: Unexpected MATLAB operator.
 
>> D=A.*B


D =


     5    12
    21    32


>> F=A\B


F =


    -3    -4
     4     5


>> E=A/B


E =


    3.0000   -2.0000
    2.0000   -1.0000


>> 
>> 
>> 
>> H=A.\B


H =


    5.0000    3.0000
    2.3333    2.0000


>> E=A./B


E =


    0.2000    0.3333
    0.4286    0.5000


>> A=[1 2 3;4 5 6;7 8 9;11 12 13]


A =


     1     2     3
     4     5     6
     7     8     9
    11    12    13


>> B=A(:,1)


B =


     1
     4
     7
    11


>> B=A(3,3)


B =


     9


>> B=A(1:3,3)


B =


     3
     6
     9


>> B=A(1:3,:)


B =


     1     2     3
     4     5     6
     7     8     9


>> B=A(1:3,:)%1到3行的所有列


B =


     1     2     3
     4     5     6
     7     8     9


>> B=A(1:3,3)%1到三行的第三列


B =


     3
     6
     9


>> B=A(3,3)%第三行第三列


B =


     9


>> B=A(:,1)%所有行的第一列


B =


     1
     4
     7
    11


>> C=[A;B]%B补在A后面
Error using vertcat
CAT arguments dimensions are not consistent.
 
>> A1=[1 2;3 4] B1=[5 6 7 8]
 A1=[1 2;3 4] B1=[5 6 7 8]
             |
Error: Unexpected MATLAB expression.
 
>> A1=[1 2;3 4] ,B1=[5 6 7 8]


A1 =


     1     2
     3     4




B1 =


     5     6     7     8


>> A1=[1 2;3 4] ,B1=[5 6 ;7 8]


A1 =


     1     2
     3     4




B1 =


     5     6
     7     8


>> A1=[1 2;3  C=[A;B]%B补在A后面
 A1=[1 2;3  C=[A;B]%B补在A后面
            |
Error: The expression to the left of the equals sign is not a valid target for an assignment.
 
>> C=[A;B]%B补在A后面
Error using vertcat
CAT arguments dimensions are not consistent.
 
>> C1=[A;B]%B补在A后面
Error using vertcat
CAT arguments dimensions are not consistent.
 
>> C=[A,B] %B补在A后面


C =


     1     2     3     1
     4     5     6     4
     7     8     9     7
    11    12    13    11


>> C=[A,B] %B补在A下面


C =


     1     2     3     1
     4     5     6     4
     7     8     9     7
    11    12    13    11


>> C1=[A;B]
Error using vertcat
CAT arguments dimensions are not consistent.
 
>> A1=[1 2;3 4] 


A1 =


     1     2
     3     4


>> B1=[5 6 7 8]


B1 =


     5     6     7     8


>> B1=[5 6 ;7 8]


B1 =


     5     6
     7     8


>> C1=[A;B]
Error using vertcat
CAT arguments dimensions are not consistent.
 
>> A2=[1 2;3 4]


A2 =


     1     2
     3     4


>> C2=[A1;A2]


C2 =


     1     2
     3     4
     1     2
     3     4


>> C2=[A1,A2]


C2 =


     1     2     1     2
     3     4     3     4


>> A3=[0 0 0 1;1 0 0 2;3 1 0 0;0 0 5 0;0 8 8 8]


A3 =


     0     0     0     1
     1     0     0     2
     3     1     0     0
     0     0     5     0
     0     8     8     8


>> R1=sparse(A)


R1 =


   (1,1)        1
   (2,1)        4
   (3,1)        7
   (4,1)       11
   (1,2)        2
   (2,2)        5
   (3,2)        8
   (4,2)       12
   (1,3)        3
   (2,3)        6
   (3,3)        9
   (4,3)       13


>> [m,n,s]=find(A3)


m =


     2
     3
     3
     5
     4
     5
     1
     2
     5




n =


     1
     1
     2
     2
     3
     3
     4
     4
     4




s =


     1
     3
     1
     8
     5
     8
     1
     2
     8


>> R1=sparse(A3)


R1 =


   (2,1)        1
   (3,1)        3
   (3,2)        1
   (5,2)        8
   (4,3)        5
   (5,3)        8
   (1,4)        1
   (2,4)        2
   (5,4)        8


>> R1=sparse(A3)%(行,列) 值


R1 =


   (2,1)        1
   (3,1)        3
   (3,2)        1
   (5,2)        8
   (4,3)        5
   (5,3)        8
   (1,4)        1
   (2,4)        2
   (5,4)        8


>> A4=[1 2 3 4 5 6 7 8 9]


A4 =


     1     2     3     4     5     6     7     8     9


>> fid=fopen('d:\test.bin','wb')


fid =


     3


>> fid=fopen('d:\test.bin','wb')%以二进制数据写入方式打开D盘下的test.bin文件,


fid =


     4


>> fwrite(fid,A4,'double')


ans =


     9


>> fwrite(fid,A4,'double')%把矩阵A4以double精度存入到句柄A4


ans =


     9


>> fclose(fid)


ans =


     0


>> fid=fopen('d:\test.bin','rb'))%以二进制数据写入方式打开D盘下的test.bin文件,
 fid=fopen('d:\test.bin','rb'))%以二进制数据写入方式打开D盘下的test.bin文件,
                             |
Error: Unbalanced or unexpected parenthesis or bracket.
 
>>  fid=fopen('d:\test.bin','rb')%以二进制数据读方式打开D盘下的test.bin文件,


fid =


     4


>> RR=fread(fid,5,'double')


RR =


     1
     2
     3
     4
     5


>> fclose
Error using fclose
Not enough input arguments.
 
>> fclose(fid)


ans =


     0


>> shows
Undefined function or variable 'shows'.
 
>> show
Undefined function or variable 'show'.
 
>> who


Your variables are:


A    A1   A2   A3   A4   B    B1   C    C2   D    E    F    H    R1   RR   ans  fid  m    n    s    


>> whos
  Name      Size            Bytes  Class     Attributes


  A         4x3                96  double              
  A1        2x2                32  double              
  A2        2x2                32  double              
  A3        5x4               160  double              
  A4        1x9                72  double              
  B         4x1                32  double              
  B1        2x2                32  double              
  C         4x4               128  double              
  C2        2x4                64  double              
  D         2x2                32  double              
  E         2x2                32  double              
  F         2x2                32  double              
  H         2x2                32  double              
  R1        5x4               128  double    sparse    
  RR        5x1                40  double              
  ans       1x1                 8  double              
  fid       1x1                 8  double              
  m         9x1                72  double              
  n         9x1                72  double              
  s         9x1                72  double
原创粉丝点击