convert cell array to string

1 view (last 30 days)
antonet
antonet on 13 Mar 2013
Dear all,
I have the matrix
A={ 'EE' [ 1]
'EE' [NaN]
'EE' [NaN]
'EE' '2'
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' '3'
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [ 4]};
I want to convert the values of the last column to strings so as to have
A={ 'EE' '1'
'EE' [NaN]
'EE' [NaN]
'EE' '2'
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' '3'
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' [NaN]
'EE' '4'};

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 13 Mar 2013
Edited: Azzi Abdelmalek on 13 Mar 2013
c2=A(:,2)
idx=cellfun(@(x) isnumeric(x)& ~isnan(x),c2)
c2=cellfun(@num2str,c2,'un',0)
A(idx,2)=c2(idx)

Categories

Find more on Numeric Types in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!