1

Say I have a cell arrays (named as 'data') as below:

'k0'    'k1'    'Agg'   'RH'    'AQ'    'fr'    'frac'  'Cel'   'R_A'   'Tot'   'AO'
1.15    1.1574  1.50    0.99    0.090   3.45    1.10    1   11x2 double     11x2 double  11x2 double

How do I get the last element or any element that I desire from the columns

'frac'  'Cel'   'R_A'
11x2 double 11x2 double  11x2 double

I tried using data{:,9}(end) to get the last element from the column 'frac', but not working.

1 Answer 1

2

The issue is that data{:,9} returns two elements.

data{:,9}

%   ans = 
%       'R_A'
%
%   ans = 
%       11 x 2 double

As a result, indexing with (end) after that isn't going to work. It looks like you only want the second row and not all of them. So something like this should work:

data{2,9}(end)

If you do want the last element from all things in column 9, then you'd need to use cellfun to do this for you.

values = cellfun(@(x)x(end), data(:,9), 'uniform', 0);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! What if I have multiple rows?
@Orangeblue The last line of my answer shows how you would do this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.