MATLAB: Finding length of a struct, excluding NaN values

lengthMATLABnan

I have a struct with the following layout:
T X Y
[0,1] [0, 1] [0,5]
[0] [2] [2]
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
I want to find the length of the struct excluding the trailing NaN values at the bottom. So in this case the length would be 2 instead of 6.
I have attached a file with some of the values that I am using and the struct shape. Thanks

Best Answer

You can do this very easily with the accepted answer to your very similar question from two months ago:
Just use the logical variable X:
>> F = @(s)all(structfun(@(a)isscalar(a)&&isnan(a),s)); % or ANY
>> X = arrayfun(F,AllData.Passive)
X =
0 0 0 0 1 1 1 1 1 1 1 0 0 0 0
>> nnz(~X)
ans = 8