'ab[c]' to this 'ab_c' ?
Show older comments
How can I convert this 'ab[c]' to this 'ab_c' ?
The letters a,b,c are for the specific example.
In the position of c could be any letter.
2 Comments
Steven Lord
on 6 Nov 2021
Edited: Steven Lord
on 6 Nov 2021
Are you trying to change a char vector containing this literal text, or are you trying to change indexing into a variable to instead have numbered names for variables?
If the latter, can you define variables with numbered names like ab_1, ab_2, ab_3, ... ? Yes. Should you do this? Generally we recommend against it. See that page for alternatives you should use instead.
Ioannis Vourvachakis
on 6 Nov 2021
Edited: Ioannis Vourvachakis
on 6 Nov 2021
Accepted Answer
More Answers (1)
C = { '10fthf[c]'
'10fthf[h]'
'10fthf[m]'
'10fthf[x]'}
cellstr(extractBefore(string(C),"[") + "_" + extractBefore(extractAfter(string(C),"["),2))
1 Comment
Ioannis Vourvachakis
on 6 Nov 2021
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!