필터 지우기
필터 지우기

How can I withdraw a colon operator from a string

조회 수: 6 (최근 30일)
Juan Rosado
Juan Rosado 2012년 8월 16일
I have a colon operator within a string input (<1x30> char) that I would like to withdraw for later plotting.
The variable input is this:
WIND = NORTHEAST WINDS 8 : 13 KNOTS
I want just the characters
'8 : 13'
and make them operate as a colon operator. I was thinking of using a variation of 'find' command, but I don't know how to tell MATLAB to find colon operators within a text string.
Can you please help?

답변 (3개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 17일
편집: Azzi Abdelmalek 2012년 8월 17일
c1='WIND = NORTHEAST WINDS 8 : 13 KNOTS'
a=regexp(c1,'[0-9]')
result=c1(min(a):max(a))

Matt Kindig
Matt Kindig 2012년 8월 17일
편집: Matt Kindig 2012년 8월 17일
Mr. Azzi's technique is more general, and I would use it for your purpose.
However, if you did want to use 'find' to locate specific characters in a text string, you can do it simply as:
a = 'WIND = NORTHEAST WINDS 8 : 13 KNOTS'
location = find(a==':');

Matt Fig
Matt Fig 2012년 8월 17일
편집: Matt Fig 2012년 8월 17일
Here is another.
str = 'WIND = NORTHEAST WINDS 8 : 13 KNOTS'; % Example string
m = regexp(str,'\d+\s*:\s*\d+','match')
% Now to make it operate as a colon operator in an expression:
N = str2num(m{1})

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by