Round in a cell array that also contains string
7 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I am trying to round figures in a cell array however in that same array I also have string types. round changes the value of the string therfore I can't use formulas like
cellfun(@(x)round(x,N),c)
I mean I don't how to integrate `isnumeric` to this formula.
Is there a fomula that knows to round only numeric number?
Thank you in advance.
0 个评论
采纳的回答
Stephen23
2019-7-24
编辑:Stephen23
2019-7-24
idx = cellfun(@isnumeric,C);
C(idx) = cellfun(@(x)round(x,N),C(idx),'uni',0)
3 个评论
Stephen23
2019-7-24
>> C = {1.234,'cat';'hat',5.6789}
C =
[1.234] 'cat'
'hat' [5.6789]
>> idx = cellfun(@isnumeric,C);
>> C(idx) = cellfun(@(x)round(x,2),C(idx),'uni',0)
C =
[1.23] 'cat'
'hat' [5.68]
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!