在点符号Matlab中使用字符串

时间:2015-07-02 12:44:30

标签: string matlab data-retrieval

我希望使用包含字符串的点表示法访问表格中的数据。我有一个字符串列表,表示表中感兴趣的列。如何使用这些字符串访问数据?我希望创建一个遍历字符串列表的循环。

例如,对于表格IEnumerator PendingMode() { while(true) { WWWForm Ping = new WWWForm (); Ping.AddField ("ClassPending", "ping"); WWW PingWWW = new WWW ("http://learn.edupal.co/login.php?action=classroom", Ping); yield return PingWWW; if (PingWWW.error != null) { Debug.LogError ("Cannot Connect to Server"); } else { string PingReturn = PingWWW.text; if (PingReturn == "Success") { Debug.Log ("Connected to Instructor"); //stop the coroutine StopCoroutine("PendingMode"); } else { yield return new WaitForSeconds(4f); } } } } ,我有列T。我有一个1x3的单元格{a b c d e}

我可以使用cols={b d e}格式(或等效的)cols检索数据,以便得到与T.cols(1)相同的结果吗?

1 个答案:

答案 0 :(得分:3)

您可以使用{花括号}和字符串作为列索引直接获取数据,就像使用单元格数组一样。

例如,让我们创建一个虚拟表(从文档中修改):

clc;
close all;


LastName = {'Smith';'Johnson';'Williams';'Jones';'Brown'};
a = [38;43;38;40;49];
b = [71;69;64;67;64];
c = [176;163;131;133;119];
d = [124 93; 109 77; 125 83; 117 75; 122 80];

T = table(a,b,c,d,...
    'RowNames',LastName)

表格如下:

T = 

                a     b      c         d     
                __    __    ___    __________

    Smith       38    71    176    124     93
    Johnson     43    69    163    109     77
    Williams    38    64    131    125     83
    Jones       40    67    133    117     75
    Brown       49    64    119    122     80

现在选择感兴趣的列并获取数据:

%// Select columns of interest
cols = {'a' 'c'};

%// Fetch data
T{:,cols}

ans =

    38   176
    43   163
    38   131
    40   133
    49   119

耶!

相关问题