MATLAB: How can remove words and split in cellarray in matlab

split cellarray matlab comma digit

for example x={'100614,Peter Beadle,131542'}; i want x= [100614,131542] my dataset have 408934 record like 'x'

Best Answer

For input:
x = {'100614,Peter Beadle,131542'}
You can use regexp to match numerical entries in your cell. The expression below matches numbers from 0-9 for 6 times since the numbers in your cell have exactly 6 digits.
x={'100614,Peter Beadle,131542'};
[tokens,matches] = regexp(x,'[0-9]{6}','match');
x = str2double(tokens{:});
For input:
x = {'100614','Peter Beadle','131542'}
Use the following:
x = {'100614','Peter Beadle','131542'};
x = str2double(x);
x(isnan(x)) = [];