MATLAB: Copy numbers by its position on cells from a textdata

cellcellfun

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)

Best 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))