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?