How can I convert a cell array into a numeric array using MATLAB replacing non-numeric values to NaN?

6 ビュー (過去 30 日間)
I have a cell array which contains numeric and non-numeric data. I need to convert this cell array into a numeric array with all the non-numerical elements set to 'NaN'.
I have tried the CELL2MAT function but this function does not work with non-numerical data types.

採用された回答

MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
The ability to automatically convert cell arrays which contain both numeric and non-numeric data types is not available in MATLAB 7.6 (R2008a).
However, there are a number of ways to programmatically achieve conversion of a cell array to numeric data. One such method using CELLFUN is shown below:
Let x be a cell array containing both numeric and non-numeric data
x = {'text', 34; 45, @(a)2*a}
Find logical indices to all numeric elements of x
numind = cellfun(@isnumeric, x);
Replace non-numeric indices with NaNs
x(~numind) = {NaN}

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

製品


リリース

R2008a

Community Treasure Hunt

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

Start Hunting!

Translated by