1
[~,~,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.

6
  • 2
    Can you share the error ? Did you test rawdata{2:end,ith col}? you have to write 'end' Commented Sep 24, 2015 at 4:37
  • >> rawdata(2:,:) . On executing this , error is "Error: Expression or statement is incorrect--possibly unbalanced (, {, or [" showing a marker | at comma symbol in expression executed. Commented Sep 24, 2015 at 4:50
  • 1
    2: is not valid Matlab syntax, you need to specify where the vector should end. Also, are you using { and } like in the question, or ( and ) like in your comment? Commented Sep 24, 2015 at 4:51
  • @David: Is there a symbol to specify till the end Commented Sep 24, 2015 at 4:52
  • 2
    Maybe read a basic Matlab introduction. ( is for arrays and function, { is for cell arrays. 2:end gives you the second to the last element of a row/column of an array. Commented Sep 24, 2015 at 4:55

2 Answers 2

1

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)

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

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.