how to use cell function to convert string to number

3 Ansichten (letzte 30 Tage)
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan am 11 Jun. 2015
Kommentiert: madhan ravi am 20 Dez. 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?

Akzeptierte Antwort

Ingrid
Ingrid am 11 Jun. 2015
a(:,2) = mat2cell(cellfun(@str2num,a(:,2)),ones(4,1),1)

Weitere Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by