how do I convert all capital letters in a string to lowercase and add a space before them?

5 ビュー (過去 30 日間)
I have a function that turns the input variable into a plot legend and output filename:
axisLabelInput = inputname(3);
labelInput = strrep(axisLabelInput,'_',' ');
legend(['Range at ' labelInput]);
print(gcf, '-depsc', '-r300', labelInput);
but this only works when the input variable is in the format input_var_1. It is far more common for the input variables to be in a different format, eg inputVar1, which looks awful in a legend entry. How can I modify my code to find all capital letters in my desired input variable, and make them lowercase and add a space beforehand, so that my legend and file output still make sense?

採用された回答

TAB
TAB 2012 年 12 月 18 日
Mystr = 'ABCDEF';
MystrLower = lower(Mystr);
MystrLowerWithSpace = [' ' MystrLower];
%---------OR----------
% In 1 line
MystrLowerWithSpace = [' ' lower(Mystr)];
See lower
  1 件のコメント
Sara
Sara 2012 年 12 月 18 日
編集済み: Sara 2012 年 12 月 18 日
Actually, I accepted that answer too soon. Sorry for not being clear, what I meant was that I wanted to put a space before every letter that had previously been capitalized. So if the input was:
inputVarOne
then the converted value would be
input var one
but the rest is perfect, thanks.

サインインしてコメントする。

その他の回答 (1 件)

Muruganandham Subramanian
Muruganandham Subramanian 2012 年 12 月 18 日
Use lower() command

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by