How can I format strings for use as structure field names in MATLAB?

I want to remove hyphens (-), slashes (/) and white space () from a string name(i) so that I can use it as a structure field name.

This is the ugly way I am currently doing it using the function strrep:

cell2mat(strrep(strrep(strrep(name(i), '-',''),'/',''),' ', ''))

I have also tried other variations, such as:

strrep(name(i),{'-','/'},{'',''});
strrep(name(i),['-','/'],['','']);

What is a more efficient way of doing this?

9
задан gnovice 29 March 2017 в 19:54
поделиться