How to delete numbers from cell?

조회 수: 2 (최근 30일)
Heidi Mäkitalo
Heidi Mäkitalo 2019년 6월 13일
댓글: Heidi Mäkitalo 2019년 6월 13일
I have a cell array that contains the following lines:
'0,31:1.03 SPEED MEASURED 1 [rpm]'
'0,31:1.04 MOTOR SPEED [rpm]'
'0,31:1.08 MOTOR TORQUE [%]'
'0,31:25.04 TORQUE REF B [%]'
I want to use them as titles for figures, but without the numbers preceding the text. For a figure that plots the measured speed, for example, I would want to have a title like this: SPEED MEASURED 1 [rpm]. How can I go about doing this?

채택된 답변

Stephen23
Stephen23 2019년 6월 13일
편집: Stephen23 2019년 6월 13일
Simpler with regexprep:
>> D = regexprep(C,'^\S+\s*','')
D =
'SPEED MEASURED 1 [rpm]'
'MOTOR SPEED [rpm]'
'MOTOR TORQUE [%]'
'TORQUE REF B [%]'
  댓글 수: 1
Heidi Mäkitalo
Heidi Mäkitalo 2019년 6월 13일
Thanks! I actually didn't know about this function, I've only heard of regexp before. Works well & looks neat!

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

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2019년 6월 13일
a = {'0,31:1.03 SPEED MEASURED 1 [rpm]'
'0,31:1.04 MOTOR SPEED [rpm]'
'0,31:1.08 MOTOR TORQUE [%]'
'0,31:25.04 TORQUE REF B [%]'};
regexp(a,'(?<=\d\.\d{2}\s+).*','match','once')

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by