how to use cell function to convert string to number

3 vues (au cours des 30 derniers jours)
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan le 11 Juin 2015
Commenté : madhan ravi le 20 Déc 2018
I have a cell array a = { 'a' '0' ; 'b' '1' ; 'c' '2' ; 'd' '3'}
so a = 'a' '0'
'b''1'
'c''2'
how can I convert the second column from string to number and should retain the cell array?

Réponse acceptée

Ingrid
Ingrid le 11 Juin 2015
a(:,2) = mat2cell(cellfun(@str2num,a(:,2)),ones(4,1),1)

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 11 Juin 2015
a = { 'a' '0' ; 'b' '1' ; 'c' '2' ; 'd' '3'}
a(:,2)=cellfun(@str2double,a(:,2),'un',0)
  2 commentaires
Supraja Murali
Supraja Murali le 20 Déc 2018
Can you explain what 'un' and '0' are in the answer above?
madhan ravi
madhan ravi le 20 Déc 2018
un-> UniformOutput 0-> false

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings 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!

Translated by