MATLAB: How to put a string variable into a Figure Title

figureMATLABplotsavefigstrings

FILE_NAME = '1.A.A';
figure('Name', 'Figure 1')
plot(X, Y, 'LineWidth', 1)
title('FILE %s: X vs Y (dB Mag)', FILE_NAME)
savefig('FILE %s: X vs Y.fig', FILE_NAME)
I have a large number of figures I'm plotting, so
I want to designate the variable FILE_NAME, and save the figures in my Current Folder.
  • Currently, I'm getting an error, "Incorrect number of input arguments"

Best Answer

You’re almost there!
Add a sprintf call and it does what you want:
title(sprintf('FILE %s: X vs Y (dB Mag)', FILE_NAME))
and:
savefig(sprintf('FILE %s: X vs Y.fig', FILE_NAME))
I tested the title call. Since I don’t want to write the file to my computer, I didn’t test the savefig call. It should work. (It would likely help to include the figure handle as the first argument in the savefig call, just to be certain it’s doing what you want it to, although that’s snot required.)
.