-
Notifications
You must be signed in to change notification settings - Fork 10
/
sulfide.m
171 lines (134 loc) · 3.59 KB
/
sulfide.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
%generic sulfide calculator
function [APFU]=sulfide(data,headers)
[m,n]=size(data); %finds the x and y size of the input data matrix
I(1,1)=find(strcmp(headers,'S'));
%makes As optional
if strcmp(headers,'As')==zeros(1,length(headers))
I(1,2)=0;
else
I(1,2)=find(strcmp(headers,'As'));
end
%makes Fe optional
if strcmp(headers,'Fe')==zeros(1,length(headers))
I(1,3)=0;
else
I(1,3)=find(strcmp(headers,'Fe'));
end
%makes Ni optional
if strcmp(headers,'Ni')==zeros(1,length(headers))
I(1,4)=0;
else
I(1,4)=find(strcmp(headers,'Ni'));
end
%makes Cu optional
if strcmp(headers,'Cu')==zeros(1,length(headers))
I(1,5)=0;
else
I(1,5)=find(strcmp(headers,'Cu'));
end
%makes Co optional
if strcmp(headers,'Co')==zeros(1,length(headers))
I(1,6)=0;
else
I(1,6)=find(strcmp(headers,'Co'));
end
%makes Pb optional
if strcmp(headers,'Pb')==zeros(1,length(headers))
I(1,7)=0;
else
I(1,7)=find(strcmp(headers,'Pb'));
end
%makes Zn optional
if strcmp(headers,'Zn')==zeros(1,length(headers))
I(1,8)=0;
else
I(1,8)=find(strcmp(headers,'Zn'));
end
%% Molecular weights
S=32.06;
Fe=55.8452;
Ni=58.693;
Cu=63.546;
Co=58.933;
Pb=207.2;
Zn=65.382;
As=74.922;
W=[S,As,Fe,Ni,Cu,Co,Pb,Zn];
%% Moles of elements
MC(:,1)=data(:,I(1,1))./W(:,1); %for S
%calculates for As if it is included in the analysis
if I(1,2)==0
MC(:,2)=zeros(m,1);
else
MC(:,2)=data(:,I(1,2))./W(:,2); %for As
end
%calculates for Fe if it is included in the analysis
if I(1,3)==0
MC(:,3)=zeros(m,1);
else
MC(:,3)=data(:,I(1,3))./W(:,3); %for Fe
end
%calculates for Ni if it is included in the analysis
if I(1,4)==0
MC(:,4)=zeros(m,1);
else
MC(:,4)=data(:,I(1,4))./W(:,4); %for Ni
end
%calculates for Cu if it is included in the analysis
if I(1,5)==0
MC(:,5)=zeros(m,1);
else
MC(:,5)=data(:,I(1,5))./W(:,5); %for Cu
end
%calculates for Co if it is included in the analysis
if I(1,6)==0
MC(:,6)=zeros(m,1);
else
MC(:,6)=data(:,I(1,6))./W(:,6); %for Co
end
%calculates for Pb if it is included in the analysis
if I(1,7)==0
MC(:,7)=zeros(m,1);
else
MC(:,7)=data(:,I(1,7))./W(:,7); %for Pb
end
%calculates for Zn if it is included in the analysis
if I(1,8)==0
MC(:,8)=zeros(m,1);
else
MC(:,8)=data(:,I(1,8))./W(:,8); %for Zn
end
%% Normalization
%prompts the user if they wish calculate on a cation or anion basis
prompt1='Do you wish to calculate on a cation basis? (y|n): ';
wantcation=input(prompt1, 's');
if strcmp(wantcation, 'y')
disp('You are calculating on a cation basis.')
prompt2='How many cations do you wish to normalize to?: ';
CM=input(prompt2);
prompt3='Do you wish to treat As as a cation? (y|n): ';
wantAs=input(prompt3,'s');
if strcmp(wantAs, 'y')
disp('As will be treated as a cation.')
NF=CM./sum(MC(:,2:8),2); %normalization factor w/ As
else
disp('As will be treated as an anion.')
NF=CM./sum(MC(:,3:8),2); %normalization factor w/o As
end
else
disp('You are calculating on an anion basis.')
prompt2='How many anions do you wish to normalize to?: ';
AM=input(prompt2);
prompt3='Do you wish to treat As as a cation? (y|n): ';
wantAs=input(prompt3,'s');
if strcmp(wantAs, 'y')
disp('As will be treated as a cation.')
NF=AM./MC(:,1); %normalization factor w/o As
else
disp('As will be treated as an anion.')
NF=AM./(MC(:,1)+MC(:,2)); %normalization factor w/ As
end
end
APFU=MC.*NF; %Normalized moles = moles of elements * normalization factor
APFU=array2table(APFU,'VariableNames',{'S','As','Fe','Ni','Cu','Co','Pb','Zn'});
end