tusharfloyd
tusharfloyd

Reputation: 1972

How to access cell array from an index i to the end

[~,~,rawdata] = xlsread('somefile');

rawdata is a cell array of 1311 x 14 cells. I want to access from second row to last row for a specified column.

like rawdata{2:,ith col} but it gives an error.

The end purpose I am trying to solve is to find NaN count for each column of a 2-D cell array imported from excel of heterogeneous format.

Upvotes: 1

Views: 542

Answers (2)

Luis Mendo
Luis Mendo

Reputation: 112759

To obtain the number of cells that equal NaN in each column, you can use

result = sum(cellfun(@(n) isequalwithequalnans(n,NaN), rawdata), 1);

For example,

rawdata = { 'aa', NaN;
            2,    NaN;
            NaN,    3 };

produces

result =
     1     2

If all of your cells contain either NaN or a number (so no strings etc), you can use the simpler

result = sum(cellfun(@isnan, rawdata), 1);

For example,

rawdata = { 1,   NaN,   3;
            2,   NaN, NaN;
            NaN,   7,   4 };

gives

result =
     1     2     1

Upvotes: 0

jebob
jebob

Reputation: 173

rawdata(2:end,ith_col) should work, as discussed in the comments.

Use end to refer to the last character in a matrix or array.

Use () to refer to a block of elements in an array or matrix. As an element of a matrix is conceptually a 1x1 matrix, myMatrix(1,3) gets the third element in the first row.

Use {} to extract a single element from an array. For example:

myCell = {'test','hello_world',56,[1;2;3]};
disp(myCell(1))
disp(myCell{1})

Would first print the 1x1 cell {'test'} (appears 'test' in the command window) and then the string 'test' (appears test)

Upvotes: 1

Related Questions