MATLAB Answers

Arman Kam
0

how to write a character from a string?

Asked by Arman Kam
on 2 Feb 2013

Hi I didn't use commands for strings in matlab so i have a word like 'displacement22' and i want to write '22' from this string, so what would i do?

  0 Comments

Products

No products are associated with this question.

3 Answers

Answer by Image Analyst
on 2 Feb 2013

s = 'displacement22' % Your string.
theNumber = sscanf(s, 'displacement%d') % Extract the number.

  0 Comments


Answer by Azzi Abdelmalek
on 2 Feb 2013
Edited by Azzi Abdelmalek
on 2 Feb 2013

s='displacement22' ;
out=s(regexp(s ,'[0-9]'))

%or

 out=s(regexp(s ,'\d'))

  0 Comments


Answer by Jan Simon
on 2 Feb 2013

s = 'displacement22';
s = strrep(s, 'displacement', '');

  0 Comments


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!