How to remove spaces and special characters from elements of a char array
Show older comments
char array names = ['time (s)', 'speed (%)',....]
I want to save the char array such that () and % characters are removed, meaning names = ['time_s', 'accel_pedal',...]
5 Comments
Paolo
on 17 Aug 2018
Where is accel_pedal coming from? Do you mean speed_% ? Can you clarify what the logic is here?
Walter Roberson
on 17 Aug 2018
Do you want to specifically remove only ( and ) and %, leaving in place anything like : or & ? Or do you have a specific set of characters you want to preserve with everything else to be changed or discarded?
If the input were 'time (s)' would you want the output to be 'time__s' or 'time_s' ?
Image Analyst
on 17 Aug 2018
I'm sure you've tried strrep(), but what was wrong with that? And do you want to replace all "special" characters with underlines, like
str = strrep(str, '%', '_');
harshpurohit11
on 18 Aug 2018
Edited: harshpurohit11
on 18 Aug 2018
Image Analyst
on 18 Aug 2018
Yes you do. It was introduced before R2006a.
Accepted Answer
More Answers (0)
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!