MATLAB: Find the last NaN value in cell array and compare it with the next column

cell arraysMATLABnan

I have a cell array with size 48×13, like can see below
48×13 cell array
Columns 1 through 12
[NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] '2460a2f3' [ 0]
[NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] '2460a6dd' [ 1]
[NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] '245f81f7' [ 0]
[NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] '245ecc3e' [ 1]
[NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] '217c7a70' [ 0]
[NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [NaN] [ NaN] [NaN]
I need to find the position of the first NaN in column 11 and compare if the previous position has a value of 0 in column 12.
To first part I already tried, the code below, to find the first NaN, but without results
ID_ii = (cellfun(@isnan,Code_Excel(:,11),'UniformOutput', false));
X = find(ID_ii,'1'),

Best Answer

  • Yeah...the nonnumeric content of the cells containing hex strings changes things...those all return a logical array and not just a single true/false.
    i1=cellfun(@(c)all(isnan(c)), A(:,11)); % A is your array, of course...

    Alternatively, if it is known that the only locations that aren't hex strings are [NaN] and there aren't other numeric values besides NaN,
    i1=cellfun(@isnumeric, A(:,11)); % A is your array, of course...