Extracting a number from cells

1 view (last 30 days)
Iwan Marshall
Iwan Marshall on 17 Dec 2020
Answered: Image Analyst on 17 Dec 2020
I am relatively new to MATLAB and I am looking for some help extracting the numbers from a cell containing letters and numbers. The format is 47 rows and 1 column with each cell containing the word 'Monday' followed by a number.
I was wondering if it is possible to extract just the number so it should say:
Apologies for the poor terminology, I am not great with the correct terms for everything.
Thank you
  1 Comment
Image Analyst
Image Analyst on 17 Dec 2020
A cell cannot contain both letters and numbers, unless the cell contained a cell array. A cell array can. Not sure what you have because you forgot to attach your cell array data
save('answers.mat', 'yourCellArray');
In the meantime, read this link:

Sign in to comment.

Answers (2)

Ameer Hamza
Ameer Hamza on 17 Dec 2020
Edited: Ameer Hamza on 17 Dec 2020
How are these strings stored? Are these stored in a cell array? If yes, try something like this
C = {'Monday06', 'Monday10', 'Monday38', 'Monday18'}
vals = textscan([C{:}], 'Monday%d')

Image Analyst
Image Analyst on 17 Dec 2020
Try isstrprop():
ca = {...
for k = 1 : numel(ca)
thisCell = ca{k};
digitIndexes = isstrprop(ca{k},'digit');
numbers(k) = str2double(thisCell(digitIndexes))


Community Treasure Hunt

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

Start Hunting!