how to use cell function to convert string to number

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?

 采纳的回答

a(:,2) = mat2cell(cellfun(@str2num,a(:,2)),ones(4,1),1)

更多回答(1 个)

a = { 'a' '0' ; 'b' '1' ; 'c' '2' ; 'd' '3'}
a(:,2)=cellfun(@str2double,a(:,2),'un',0)

2 个评论

Can you explain what 'un' and '0' are in the answer above?
un-> UniformOutput 0-> false

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by