Loading multiple spectra simultaneously from a folder

General forum for EasySpin: questions, how to's, etc.
Post Reply
katarkon
Local Expert
Posts: 197
Joined: Mon Jan 12, 2015 4:01 am

Loading multiple spectra simultaneously from a folder

Post by katarkon »

Magnettech MS-5000 spectrometer saves 2D experiments (like temperature series) as a set of the separate files in dedicated folder. For some simulations it is convenient to load all of the spectra simultaneously. I see EasySpin has no built-in possibilities for it, so additional wrapper around eprload is required. Am I right?

Stefan Stoll
EasySpin Creator
Posts: 1120
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Loading multiple spectra simultaneously from a folder

Post by Stefan Stoll »

Indeed, eprload loads a single data file. To load multiple file, write a for loop. Example:

Code: Select all

T = 100:10:200;  % temperature
for iT = 1:numel(T)
  filename = sprintf('mydata_%dK',T(iT));
  [B,spc(iT,:)] = eprload(filename);
end
katarkon
Local Expert
Posts: 197
Joined: Mon Jan 12, 2015 4:01 am

Re: Loading multiple spectra simultaneously from a folder

Post by katarkon »

Thanks for idea. I try slightly different code:

Code: Select all

path='foldername\';
list=dir(path);
for i=1:numel(list)
    if list(i).isdir ==0
        [x,y,par]=eprload([path list(i).name]);
        % 
        % combine spectra here
        %
    end
end

You way looks more convenient if adopted for MS-5000 file naming.
Unfortunately, the MS-5000 files in series have slightly different numbers of datapoints and spectral range, so [B,spc(iT,:)] = eprload(filename); will throw an error of dimension mismatch.
I think the best way will be loading the spectra in a cell array instead of 2D matrix.

Stefan Stoll
EasySpin Creator
Posts: 1120
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Loading multiple spectra simultaneously from a folder

Post by Stefan Stoll »

Looks good! Here is a modification that skips

Code: Select all

folder = 'foldername';
xmlfiles = dir([folder filesep '*.xml');
for i = 1:numel(xmlfiles)
    [B{i},spc{i},par{i}] = eprload([path filesep xmlfiles(i).name]);
end
Post Reply