MATLAB: Remove NaN from doubles within a cell array

cell arraysnan

For example, how would I get this:
ab = {[1 2 NaN 3 4];[1 3 4 NaN 5 6 7 NaN]}
to output
ab = {[1 2 3 4];[1 3 4 5 6 7]}
I've tried
ab(cellfun(@(x) all(isnan(x)),ab)) = []
but it doesn't work

Best Answer

Try this:
ab = {[1 2 NaN 3 4];[1 3 4 NaN 5 6 7 NaN]};
Output = cellfun(@(x) x(isfinite(x)), ab, 'UniformOutput',false);
Out1 = Output{1} % Display Output (Delete)

Out2 = Output{2} % Display Output (Delete)
Out1 =
1 2 3 4
Out2 =
1 3 4 5 6 7