MATLAB Answers

0

How to delete numbers from cell?

Asked by Heidi Mäkitalo on 13 Jun 2019
Latest activity Commented on by Heidi Mäkitalo on 13 Jun 2019
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?

  0 Comments

Sign in to comment.

2 Answers

Answer by Stephen Cobeldick on 13 Jun 2019
Edited by Stephen Cobeldick on 13 Jun 2019
 Accepted Answer

Simpler with regexprep:
>> D = regexprep(C,'^\S+\s*','')
D =
'SPEED MEASURED 1 [rpm]'
'MOTOR SPEED [rpm]'
'MOTOR TORQUE [%]'
'TORQUE REF B [%]'

  1 Comment

Thanks! I actually didn't know about this function, I've only heard of regexp before. Works well & looks neat!

Sign in to comment.


Answer by Andrei Bobrov
on 13 Jun 2019

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')

  1 Comment

Thanks for the answer!

Sign in to comment.