for loop to convert cells of column to string

조회 수: 1 (최근 30일)
Amr Hashem
Amr Hashem 2015년 5월 19일
답변: Amr Hashem 2015년 5월 20일
i have a data which is a column of cells (some string and some douple), i search for some words in it
i use this code
for E=1:R % from 1 : length of columns
B=~cellfun('isempty',regexp(alldata(:,52),'BATTERY')) % search for battrey and return 1 or 0
if (B(E) == 1) % if value of array greater than or equal 1
Defs(j)=E; % save its postion (E,1)
j=j+1;
else % save all arrays didn't have 'battery' separately
not(k)=E;
k=k+1;
end
end
but i get an error
All cells must be strings.
in line B=~cellfun('isempty',regexp(alldata(:,52),'BATTERY'))
how i can run a for loop to convert all cells into double?
i use this
data= ' Nan '
data={};
data{ not( cellfun( @ischar, data ) ) } = '';
but i cant run a for loop... :(
  댓글 수: 1
Amr Hashem
Amr Hashem 2015년 5월 19일
sometimes when i search for a word in a column
with the same code, i got this error Index exceeds matrix dimensions.
B=~cellfun('isempty',regexp(alldata(:,54),'BATTERY'))
it seems that some cells in the column is empty
how i can solve this

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

채택된 답변

Amr Hashem
Amr Hashem 2015년 5월 20일
I found this answer:
[R,C]=size(data);
H=data;
for k = 1:R
if isnan(H{k})
H{k} = '';
end
end
it was answered by Jan Simon
and it works...
thanks for you all... thanks for Jan.

추가 답변 (0개)

카테고리

Help CenterFile 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