cellfun(@(x)(x(7:end)), A, 'UniformOutput', false)
or if you want them as numbers then
cellfun(@(x)(str2num(x(7:end))), A)
Question
I have a Matlab cell array, A <118080 x 1 cell> that look something like this:
"Point 1"
"Point 2"
"Point 3"
...
"Point 1230"
The cells are char cells of between 1x9 and 1x12 dimensions.
I need to seperate the numbers from these fields to give a 118080 x 1 matrix like:
1
2
3
...
1230
Any help would be greatly appreciated.
Best
Sam (A Matlab Newbie)
Solution 2
cellfun(@(x)(x(7:end)), A, 'UniformOutput', false)
or if you want them as numbers then
cellfun(@(x)(str2num(x(7:end))), A)
OTHER TIPS
A solution without cellfun
that uses regexp
(only the numbers are kept here)
A = {'Point 1'
'Point 222'
'Point 33333'}
B = regexp(A, '\d+', 'match'); %produce a cell array of numbers in string format
If you want to convert the cells into a matrix
B = str2double([B{:}])'; %convert to numbers