How to delete the first or the first two characters in a string?

303 views (last 30 days)
Philipp Mueller
Philipp Mueller on 15 May 2020
Answered: the cyclist on 28 Apr 2022 at 16:24
How can i delete the first two characters of this string? Thank you

Accepted Answer

KSSV on 15 May 2020
Edited: KSSV on 15 May 2020
string(1:2) = [] % To remove the firt two elements

More Answers (1)

the cyclist
the cyclist on 28 Apr 2022 at 16:24
In modern MATLAB parlance, 'W987' is a character array, not a string.
@KSSV's answer is accurate in your case, but will not work on the string "W987". The following will work for either a character array or a string:
c = 'W987';
ans = '87'
s = "W987";
ans = "87"


Community Treasure Hunt

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

Start Hunting!