What's the difference between {} and [] in MATLAB?

前端 未结 5 460
清酒与你
清酒与你 2021-01-03 03:57
>> A={1 2;2 3}

A = 

    [1]    [2]
    [2]    [3]
>> A=[1 2;2 3]

A =

     1     2
     2     3

It seems to me they are essentially

5条回答
  •  甜味超标
    2021-01-03 04:15

    Elements of different data types which get inside {} become cells or elements of data type cell. Elements inside [] retain their data type and make an array of that data type. Few examples below:

    p = ['my', 'string'];
    q = [int8(1), int8(2), int8(3)];
    r = [0.11, 0.22, 0.33];
    s = {'my', 'string'};
    t = {1,2,3};
    u = {0.11, 0.22, 0.33};
    v = {int8(1), int8(2), int8(3)};
    
    >> whos
      Name      Size            Bytes  Class     Attributes
    
      p         1x8                16  char                
      q         1x3                 3  int8                
      r         1x3                24  double              
      s         1x2               240  cell                
      t         1x3               360  cell                
      u         1x3               360  cell                
      v         1x3               339  cell 
    

提交回复
热议问题