MATLAB: The value assigned to variable ‘g3’ might be unused

gaussianMATLAB

I am writing code and plotting a guassian chart and when i do it a guassian chart comes up but i do not know if it is correct and i am getting the error that the value assigned to variable 'g3' might be unused, here is my code below
function guasmem1
x= 2; % given x value
v= 0; % centre, e.g. 0
s= 2; % width >0
% calculate degree of membership (g3) for a given x
g1=(x-v)/s;
g2=abs(g1);
g3=exp(-(1/2)*(g2.^2));
%plotting membership func for centre (V) and width (S)
% can define v1 in anyway, needs different min and max
% values
v1=(v-6):((1+abs(v))/100):(v+6);
g1=(v1-v)/s;
g2=abs(g1);
g3= exp(-(1/2)*(g2.^2));
plot(v1,g3)
end

Best Answer

It is not a mistake, it is a warning and it is because that value that you calculate of g3 for the first time you do not use it anywhere and it is lost when you recalculate g3
function guasmem1
x= 2; % given x value
v= 0; % centre, e.g. 0
s= 2; % width >0
% calculate degree of membership (g3) for a given x
g1=(x-v)/s;
g2=abs(g1);
g3=exp(-(1/2)*(g2.^2));% you do not use it anywhere
%plotting membership func for centre (V) and width (S)
% can define v1 in anyway, needs different min and max
% values
v1=(v-6):((1+abs(v))/100):(v+6);
g1=(v1-v)/s;
g2=abs(g1);
g3= exp(-(1/2)*(g2.^2)); %here the previous value is lost
plot(v1,g3)
end