Round in a cell array that also contains string
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jack Arnoldi
le 24 Juil 2019
Commenté : Jack Arnoldi
le 24 Juil 2019
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 commentaires
Réponse acceptée
Stephen23
le 24 Juil 2019
Modifié(e) : Stephen23
le 24 Juil 2019
idx = cellfun(@isnumeric,C);
C(idx) = cellfun(@(x)round(x,N),C(idx),'uni',0)
3 commentaires
Stephen23
le 24 Juil 2019
>> 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]
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!