Kiran
Kiran

Reputation: 8528

Extract a single column from a matrix

I have a matrix generated from the program written in Matlab something like this :

     '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]

I am trying to extract the column 'D' without the header 'D'.

I can put into a temporary variable and then extract the column data. But I am wondering, if it could be done in a single step.

Thanks

Upvotes: 1

Views: 8635

Answers (1)

Pursuit
Pursuit

Reputation: 12345

If your variable is data, then data(2:end,4) should do it.


Edit:

For example:

>> 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

Upvotes: 6

Related Questions