Minimalist
Minimalist

Reputation: 975

Matlab: Save jpg Files Under Plot Title Name

In MATLAB, I have a collection of simple plots with the titles displaying:

  Indiana
  Montana 
  Texas
  Arizona

I need to take these plots and save the plots as jpg files by their TITLE name in a folder named States:

 Folder:States
 Indiana.jpg
 Montana.jpg
 Texas.jpg
 Arizona.jpg

Thanks,

Amanda

Upvotes: 1

Views: 1268

Answers (1)

Molly
Molly

Reputation: 13610

The following code will save all the currently open figures with their title as the file name.

figHandles = get(0,'Children'); % gets the handles to all open figure

for f = figHandles'
    axesHandle = get(f,'Children'); % get the axes for each figure
    titleHandle = get(axesHandle(1),'Title'); % gets the title for the first (or only) axes)
    text = get(titleHandle,'String'); % gets the text in the title
    saveas(f, text, 'jpg') % save the figure with the title as the file name 
end

Upvotes: 1

Related Questions