Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

extracting a number from a cell

조회 수: 1 (최근 30일)
joseph Frank
joseph Frank 2012년 2월 11일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi,
I have a vector where each cell has the following format:
OHN HANCOCK LF.IN. 2004 5.32% 15/04/14 INDXLK.
ARIZONA PUB.SVS. 1992 8 3/4% 15/01/24 EARLY
is there a way to extract the date 15/05/14 from the cell?
  댓글 수: 1
Image Analyst
Image Analyst 2012년 2월 11일
Not from that one because it's not in there.
But in general
theString = ca{3}; % Or whatever cell it's in
substring = theString(index1:index2);

답변 (1개)

Image Analyst
Image Analyst 2012년 2월 11일
For example:
ca = {'OHN HANCOCK LF.IN. 2004 5.32% 15/04/14 INDXLK. ARIZONA PUB.SVS. 1992 8 3/4% 15/01/24 EARLY'}
theString = ca{1}
theDate = theString(30:38)
Results in command window:
ca =
'OHN HANCOCK LF.IN. 2004 5.32% 15/04/14 INDXLK. ARIZONA PUB.SVS. 1992 8 3/4% 15/01/24 EARLY'
theString =
OHN HANCOCK LF.IN. 2004 5.32% 15/04/14 INDXLK. ARIZONA PUB.SVS. 1992 8 3/4% 15/01/24 EARLY
theDate =
15/04/14
  댓글 수: 2
joseph Frank
joseph Frank 2012년 2월 11일
the issue is that each cell has a different length "OHN HANCOCK LF.IN. 2004 5.32% 15/04/14 INDXLK" is one cell and "ARIZONA PUB.SVS. 1992 8 3/4% 15/01/24 EARLY" is another one
Image Analyst
Image Analyst 2012년 2월 11일
Use strfind() to find the first slash, then back up until you hit a space. Or else find the % symbol, move up two characters and then find the first space after that and take everything in between. I think you should be able to figure it out once you look up strfind() in the help.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by