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)

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 3 Nov. 2014
Bearbeitet: Azzi Abdelmalek am 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 Kommentare

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by