-1

In the workspace I have many m-files containing data I'd like to plot. I have to read them all and save their plot without showing the results (I'll see them after all is done). The last part can be done this way?

f = figure('Visible', 'off');
plot(x,y);
saveas(f,'figure.fig');

but I don't want to load manually each m-file where x and y are stored. So I need a way to explore the filesystem and run these statements for each file, manipulate their name and save a jpg with the same name of its m-file.

user3290180
  • 3,590
  • 9
  • 38
  • 69

1 Answers1

0

The dir function will return a structure containing info on the Folders and Files in the current directory

>> FileInfo = dir

Then you need to write code to use that info to automatically navigate the directory structure (using cd for instance), and select the files you want to read.

The function what can also be useful if you're wanting to only look for certain file types, e.g. .mat files.

Not surprisingly, similar questions to this have been asked before, for instance see here

Community
  • 1
  • 1
Phil Goddard
  • 10,286
  • 1
  • 13
  • 25