MATLAB Answers


How to remove numbers between specific symbols in text array?

Asked by Joseba Moreno on 14 Feb 2019 at 8:44
Latest activity Edited by madhan ravi
on 14 Feb 2019 at 10:23
Hello everyone,
I have a question regarding how to modify a text array in Matlab which contains numbers between two "_" symbols. Here some examples:
  • If the string has the following structure: "Gas_1_O2" I expect the following result: "Gas_O2". This should work for every number between two "_" symbols.
  • If the string has another structure nothing should happen (e.g. "Time" or "Flow_Fluidization").
The text string will later on be used for renaming a table.
I tried with the function extractBetween but it did not worked as I expected.
Thanks for your support.


Sign in to comment.

3 Answers

Answer by madhan ravi
on 14 Feb 2019 at 8:54
 Accepted Answer



In that case:
"The code was put keeping only numbers (including decimals)..."
Remember that . by itself matches all characters, not just the decimal point / period chraacter.
True Stephen that‘s why I used [\.] to preserve dot character in the latter comment.

Sign in to comment.

Answer by Rik Wisselink on 14 Feb 2019 at 8:52

You can use regular expressions for this task:


Sign in to comment.

Answer by Joseba Moreno on 14 Feb 2019 at 9:14

Hello again,
the script works good, thanks for it. I am facing now a minor problem with "duplicate variable names", due to the following reason:
Before renaming: "Temp_01_free", "Temp_02_free", etc.
After renaming: "Temp_free" in all cases. Is it possible to number the variables then as long as they are repeated? For instance: "Temp_free1", "Temp_free2", etc.
Thanks again!

  1 Comment

Why are you numbering variable names? That's a bad idea.

Sign in to comment.