clear
clc
ds = tabularTextDatastore('D:\NMR_data\change it to the folder','FileExtensions','.asc');
[size_ds,~] = size(ds.Files);
for i = 1: size_ds
%% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 3);
% Specify range and delimiter
opts.DataLines = [2, Inf];
opts.Delimiter = "\t";
% Specify column names and types
opts.VariableNames = ["X", "Real", "Imaginary"];
opts.VariableTypes = ["double", "double", "double"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Import the data
ClamcontrolB71PRESATURATIONFT1 = readtable(ds.Files{i,1}, opts);
first_sample = readtable(ds.Files{1,1}, opts);% first sample to ensure the size is correct
first_data = table2array(first_sample);
first_data(find(first_data(:,1)<=-0.5),:) =[];
first_data(find(first_data(:,1)>=10),:) =[];
[m1,n1] = size(first_data);
%% Convert to output type
clam_data = table2array(ClamcontrolB71PRESATURATIONFT1);
clam_data(find(clam_data(:,1)<=-0.5),:) =[];
clam_data(find(clam_data(:,1)>=10),:) =[];
ppm_1 = clam_data(1:1:m1-2,1);
table_1(:,i) = clam_data(1:1:m1-2,2);
%% Clear temporary variables
clear opts
end
table_1 = table_1+ones(size(table_1))*0;
a_min = min(table_1(1:8000,:));
table_1 = table_1-ones(size(table_1)).*a_min;
final_table = [ppm_1, table_1];
save('final_table','final_table')
save('table_1','table_1')
save('ppm_1','ppm_1')
plot (ppm_1,table_1)
set(gca,'XDir','reverse')
csvwrite('final_table.csv',final_table);
%% plot the smoothed average data
table_aver = mean(table_1');
B = smoothdata(table_aver,'gaussian',5);
C = smoothdata(table_aver,'gaussian',10);
D = [ppm_1,C'];
save('smoothed_table','D')
%writematrix(D,'1r','Delimiter','\t')
sample_name = ds.Files;
save('sample_name','sample_name')
%% Plot all the data to check the potenitla problems
plot(ppm_1,table_1)
set(gca,'xdir','reverse')
legend('Small Window','Large Window')