How do I remove NaN values from a cell array?

8 ビュー (過去 30 日間)
Victoria Dutch
Victoria Dutch 2019 年 11 月 6 日
編集済み: Matt J 2019 年 11 月 6 日
I'm editing some code I was given to read in spreadsheet data collected in the field into Matlab. Some of the cells in these spreadsheets are merged, and so when I read those in, I get cells that look like ['number' 'NaN' 'number' 'NaN' ...]. I want to convert the cells to matrices, but cell2mat doesn't work when the cells contain data other than numbers. I'm trying to use "rmmissing", but get the following error:
matlab_errormessage.PNG
I suppose the obvious solution would be to unmerge the cells in the spreadsheets, but there's a lot of them, and I want to see if there's a quicker way I can do this in Matlab once that data is imported.

採用された回答

Matt J
Matt J 2019 年 11 月 6 日
編集済み: Matt J 2019 年 11 月 6 日
The presence of NaNs isn't the problem. The problem is that the cell contents are character vectors of different lengths. You can convert them like so,
>> str2double({'1','2';'NaN','40'})
ans =
1 2
NaN 40

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by