Copy numbers by its position on cells from a textdata

Dear all, i have a textdata from an .CSV. at following form. My cell file is time=( 12:11:23.4; 12:11:23.8; 12:11:24.0; 12:11:24.6; 12:11:25.2; etc) How can i create for example dsec=( 4; 8; 0; 6; 2; etc) on different cells in the same column? I tried cellfun(@(x) x(9),time(cellfun('length',time)),'un',0) but it takes only the first value 4 and puts it into every cell in the whole column. dsec=( 4 4 4etc)

 Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 3 Nov 2014
Modifié(e) : Azzi Abdelmalek le 3 Nov 2014
time={'12:11:23.4'
'12:11:23.8'
'12:11:24.0'
'12:11:24.6'
'12:11:25.2'}
out=cellfun(@(x) str2num(x{1}),regexp(time,'(?<=\.).+','match'))
%or for your case
a=char(time)
b=str2num(a(:,10))

2 commentaires

for God! it works!! thanks a lot Mr. Abdelmalek
Kostas P
Kostas P le 3 Nov 2014
Modifié(e) : Kostas P le 3 Nov 2014
well, with out=cellfun(@(x)..... how can i copy also the first and second element? fourth fifth etc

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Christmas / Winter dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by