Page 1 of 1

Loading multiple spectra simultaneously from a folder

Posted: Wed May 26, 2021 1:50 am
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?


Re: Loading multiple spectra simultaneously from a folder

Posted: Wed May 26, 2021 10:20 am
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

Re: Loading multiple spectra simultaneously from a folder

Posted: Wed May 26, 2021 11:49 pm
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.


Re: Loading multiple spectra simultaneously from a folder

Posted: Thu May 27, 2021 9:44 am
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