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

Posted by Elpezmuerto on Stack Overflow See other posts from Stack Overflow or by Elpezmuerto
Published on 2010-11-16T18:39:55Z Indexed on 2010/12/31 5:54 UTC
Read the original article Hit count: 149

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?

© Stack Overflow or respective owner

Related posts about matlab

Related posts about string-manipulation