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

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

Arman Kam

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

Image Analyst
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

Azzi Abdelmalek
Answer by Jan Simon on 2 Feb 2013
s = 'displacement22';
s = strrep(s, 'displacement', '');

0 Comments

Jan Simon

Contact us