how to use cell function to convert string to number

조회 수: 2 (최근 30일)
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2015년 6월 11일
댓글: madhan ravi 2018년 12월 20일
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?

채택된 답변

Ingrid
Ingrid 2015년 6월 11일
a(:,2) = mat2cell(cellfun(@str2num,a(:,2)),ones(4,1),1)

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 6월 11일
a = { 'a' '0' ; 'b' '1' ; 'c' '2' ; 'd' '3'}
a(:,2)=cellfun(@str2double,a(:,2),'un',0)
  댓글 수: 2
Supraja Murali
Supraja Murali 2018년 12월 20일
Can you explain what 'un' and '0' are in the answer above?
madhan ravi
madhan ravi 2018년 12월 20일
un-> UniformOutput 0-> false

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by