• matlab中数据结构之tables


      作为matlab中的一种数据结构,是一种按行和列存储信息的一种表格式的数据结构,同一列中的数据具有相同的长度,和我们平常见到的表差不多。使用关键table函数创建,格式为tableName = table(2thCol, 3thCol, ..., 'RowNames', 1thCol),当然需要提前准备一些数据。

    请看:

     1 >> names = ["Harry"; "Sally"; "Jose"]
     2 names = 
     3   3×1 string array
     4     "Harry"
     5     "Sally"
     6     "Jose"
     7 >> weights = [185; 133; 210]
     8 weights =
     9    185
    10    133
    11    210
    12 >> heights = [74; 65.4; 72.2]
    13 heights =
    14    74.0000
    15    65.4000
    16    72.2000
    17 >> patients = table(weights, heights, 'RowNames', names)
    18 patients =
    19   3×2 table
    20              weights    heights
    21              _______    _______
    22     Harry      185         74  
    23     Sally      133       65.4  
    24     Jose       210       72.2  

    第1行创建names列向量

    第7行创建weights列向量

    第12行创建heights列向量

    第17行创建table,表中必须明确指定行表头,并用'RowNames'关键字,提前说明。

    table和矩阵的使用差不多,也有自己的特殊方便之处,请看

    >> patients(:,1)
    ans =
      3×1 table
                 weights
                 _______
        Harry      185  
        Sally      133  
        Jose       210  
    >> patients(:, 'weights')
    ans =
      3×1 table
                 weights
                 _______
        Harry      185  
        Sally      133  
        Jose       210  
    >> patients({'Harry' 'Jose'}, :)
    ans =
      2×2 table
                 weights    heights
                 _______    _______
        Harry      185         74  
        Jose       210       72.2  
    >> patients(1:2:3, :)
    ans =
      2×2 table
                 weights    heights
                 _______    _______
        Harry      185         74  
        Jose       210       72.2 

    怎么样,你是学会了,还是学废了,务必好好理解。

  • 相关阅读:
    騎士宣言
    [洛谷P1631] 序列合并
    [HNOI2006]公路修建问题
    [洛谷2068] 统计和
    [洛谷P1168] 中位数
    【模板】可持久化数组(可持久化线段树/平衡树)
    【模板】可持久化线段树 1(主席树)
    [JSOI2008]最大数maxnumber
    NOI导刊2010提高(06) 黑匣子
    [洛谷1533] 可怜的狗狗
  • 原文地址:https://www.cnblogs.com/guochaoxxl/p/16629804.html
Copyright © 2020-2023  润新知