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)

 Accepted Answer

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 Comments

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

Sign in to comment.

More Answers (0)

Categories

Find more on Christmas / Winter in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!