Can I convert empty strings to NaNs automatically in a cell array?

In MATLAB, I have a cell array containing nonempty strings, numbers, and empty strings. I want to change the empty strings to NaNs using a MATLAB function.

 採用された回答

MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日

6 投票

The CELLFUN command provides this functionality:
% Return a boolean array named 'empties' (with same dimensions as cell array
% 'A') with true for each empty element and false otherwise
empties = cellfun('isempty',A);
% Now change all the empty cells in A from empty strings '' to double NaN
A(empties) = {NaN};

その他の回答 (0 件)

製品

リリース

R2006b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by