For loops and figure window title

I have several figures. I want the title of the window figure to say the basename of the file belonging to the figure. The figures are in a loop. So the code for looping the figures without overwriting one another is:
figure(i)
but how can I change this title to my basename?

 Accepted Answer

figure('Name',basename{k},'NumberTitle','off')

6 Comments

Should I put this in the loop or outside of the loop? I also get the following error: Cell contents reference from a non-cell array object.
inside the loop, 'k' is my iterator. I assumed you'd store different title names or the filenames in a cell array, which in my example is called basename. To be more explicit,
basename = {'data1','data2'};
%something here
for k = 1:numel(basename)
figure('Name',basename{k},'NumberTitle','off')
%plot here
end
for i=1:length(myfiles)
filename = fullfile(mydir1, myfiles(i).name);
[~, basename, ext] = fileparts(filename);
based on this script, the basename is obtained. How should I enter your script in here?
You're extracting the file name inside the for loop already so you could ignore the iterator 'k', so it would be just,
figure('Name',basename,'NumberTitle','off')
Yes, I tried this as well but unfortunately 2 out of the 3 figures get plotted correctly (each figure has 4 subplots), but 1 out of the 3 opens a whole new figure without a basename title with one subplot.. I do not know how to fix this..
It's hard to guess why without knowing more details. Try to set a breakpoint and run it step by step maybe.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Asked:

on 3 Nov 2017

Commented:

KL
on 3 Nov 2017

Community Treasure Hunt

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

Start Hunting!