フィルターのクリア

How to keep 0s when converting data type?

2 ビュー (過去 30 日間)
Lexington Stoyell
Lexington Stoyell 2018 年 3 月 21 日
編集済み: Jan 2018 年 3 月 21 日
I currently have a 6x4 cell. Most of the cells are populated with numbers, while the remaining have zeros. Using 'isnumeric' I have checked that the cells that contain numbers are actually characters, while those with zeros are numbers. I would like to convert the characters to numbers but am unsure how to do so and keep the zeros (they "disappear" when performing str2num since they are already numbers. How do I standardize a way to search for the characters/zeros and then have them all be numbers?
  1 件のコメント
Jan
Jan 2018 年 3 月 21 日
Posting some example data would be useful.

サインインしてコメントする。

採用された回答

Jan
Jan 2018 年 3 月 21 日
編集済み: Jan 2018 年 3 月 21 日
As far as I understand you have something like this:
C = {'123', 0, '456.4'; ...
0 '987', '3.14'}
Now convert all char vectors to numbers:
index = cellfun('isclass', C, 'char');
C(index) = num2cell(str2double(C(index)))
C = {123, 0, 456.4; ...
0 987, 3.14}
Does this match your needs?

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by