从矩阵中提取单个列

时间:2011-12-09 14:32:25

标签: matlab matrix

我有一个用Matlab编写的程序生成的矩阵,如下所示:

     'A'               'B'             'C'              'D'          'E'  
    [       4]    [          1]    [  0.9837]    [      0.9928]    [0.9928]
    [       4]    [          1]    [  0.9995]    [      0.9887]    [0.9995]
    [       4]    [          1]    [  0.9982]    [      0.9995]    [0.9995]
    [       4]    [          1]    [  0.9959]    [      0.9982]    [0.9887]

我正在尝试提取列'D'而没有标题'D'。

我可以放入一个临时变量,然后提取列数据。但我想知道,如果可以一步完成。

由于

1 个答案:

答案 0 :(得分:6)

如果您的变量为data,那么data(2:end,4)就应该这样做。

<小时/> 编辑:

例如:

>> data
data = 
    'A'    'B'    'C'         'D'         'E'     
    [4]    [1]    [0.9837]    [0.9928]    [0.9928]
    [4]    [1]    [0.9995]    [0.9887]    [0.9995] 
    [4]    [1]    [0.9982]    [0.9995]    [0.9995]
    [4]    [1]    [0.9959]    [0.9982]    [0.9887]
>> data(2:end,4)  %Extract the data as a cell array
ans = 
    [0.9928]
    [0.9887]
    [0.9995]
    [0.9982]
>> cell2mat(data(2:end,4))  %Convert to a numeric (typical) array
ans =
    0.9928
    0.9887
    0.9995
    0.9982