MATLAB Answers

convert cell array to string

9 views (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'};

  0 Comments

Sign in to comment.

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)

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags