Extracting a number from cells

조회 수: 2 (최근 30일)
Iwan Marshall
Iwan Marshall 2020년 12월 17일
답변: Image Analyst 2020년 12월 17일
Hi,
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.
e.g.
Monday06
Monday10
Monday38
Monday18
I was wondering if it is possible to extract just the number so it should say:
06
10
38
18
Apologies for the poor terminology, I am not great with the correct terms for everything.
Thank you
  댓글 수: 1
Image Analyst
Image Analyst 2020년 12월 17일
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:

댓글을 달려면 로그인하십시오.

답변 (2개)

Ameer Hamza
Ameer Hamza 2020년 12월 17일
편집: Ameer Hamza 2020년 12월 17일
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 2020년 12월 17일
Try isstrprop():
ca = {...
'Monday06'
'Monday10'
'Monday38'
'Monday18'}
for k = 1 : numel(ca)
thisCell = ca{k};
digitIndexes = isstrprop(ca{k},'digit');
numbers(k) = str2double(thisCell(digitIndexes))
end

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by