Replacing non-integer values
古いコメントを表示
I have an array of all numeric values but it is a mix of integers and non-integers. How could I replace an non-integer with 0, for example? Also, the array is fairly large (about 130k rows).
Thanks in advance!
回答 (2 件)
Azzi Abdelmalek
2013 年 12 月 6 日
a(ceil(a)~=a)=0
If 'a' is your array then use the following:
a(arrayfun(@(x) ~isinteger(x), a)) = 0;
8 件のコメント
Muneer
2013 年 12 月 6 日
sixwwwwww
2013 年 12 月 6 日
iit works for integer type values only. if you have data in default MATLAB format(double type) then you should use the following:
a(arrayfun(@(x) mod(x, 1) ~= 0, a)) = 0
Because in case of default MATLAB format data it will make all the values 0 because they are not integer
Muneer
2013 年 12 月 6 日
Azzi Abdelmalek
2013 年 12 月 6 日
Why arrayfun?
sixwwwwww
2013 年 12 月 6 日
it could be done both ways but I am learning about arrayfun and cellfun as well so I used it. Since both solutions work well so I posted this one
Muneer
2013 年 12 月 6 日
sixwwwwww
2013 年 12 月 6 日
you are welcome
カテゴリ
ヘルプ センター および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!