FMdir = dir('*FM*.ep');
FMn = numel(FMdir);
InMdir = dir('*InM*.ep');
InMn = numel(InMdir);
if (FMn ~= InMn)
error('Insufficient number of file pairs, please check naming and try again')
end
for n= 1:FMn
finalname = FMdir(n).name;
end
start = 1;
out = n;
for i = start:out
num_strfinal = num2str(i, '%02.f');
number = string(num_strfinal);
FM = dir('C:\Users\n\Desktop\F-DAS Matlab\ProcessFiles\*FM'+ number + '_*.ep');
FinalM = getfield(FM, 'name');
IN = dir('C:\Users\n\Desktop\F-DAS Matlab\ProcessFiles\*InM'+ number + '_*.ep');
InitialM = getfield(IN, 'name');
opts = detectImportOptions(FinalM, 'FileType','text');
opts.DataLines = [1, Inf];
opts.Delimiter = ",";
opts.VariableNames = ["sam12mark", "dashcolorforcolumn2"];
opts.VariableTypes = ["double", "double"];
opts.ImportErrorRule = "omitrow";
opts.MissingRule = "omitrow";
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
Final = readtable(FinalM, opts);
opts = detectImportOptions(InitialM, 'FileType','text');
opts.DataLines = [1, Inf];
opts.Delimiter = ",";
opts.VariableNames = ["sam12mark", "dashcolorforcolumn2"];
opts.VariableTypes = ["double", "double"];
opts.ImportErrorRule = "omitrow";
opts.MissingRule = "omitrow";
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
Initial = readtable(InitialM, opts);
Difference = Final{:,2} - Initial{:,2};
subplot (2,1,1)
semilogx(Initial{:,1},Initial{:,2})
title('Final & Initial Measurements')
xlabel ('Frequency'); ylabel('Magnitude')
hold on
semilogx(Final{:,1},Final{:,2})
xlabel ('Frequency (Hz)'); ylabel('Magnitude (dB)');
legend('InM','FM');
hold off
subplot (2,1,2)
semilogx(Initial{:,1},Difference(:,1))
title('Calculated Difference')
xlabel ('Frequency (Hz)'); ylabel('Magntiude (dB)')
legend('FM', 'InM')
saveas(gcf, 'figure.fig' )
saveas(gcf, 'figure.png')
if ~exist('C:\Users\n\Desktop\F-DAS Matlab\Figures', 'dir')
mkdir('C:\Users\n\Desktop\F-DAS Matlab\','Figures');
end
movefile *.fig 'C:\Users\n\Desktop\F-DAS Matlab\Figures'
movefile *.png 'C:\Users\n\Desktop\F-DAS Matlab\Figures'
end