Dear Group,
Please look at the Figure 1 and read the question below:
y  * * * *  Load cell calibration data
 * *
 * *
 * Pt. a *
0 ______________* Pt. b ______ x


Figure 1
In Figure 1 you have a set of load cell data. The thing is, the beginning and end points (Pt. and Pt. b) are above the "y" axis and away from the "x" axis i.e. they are not zeroed.
The following function was written to fix this problem, but it has an inherent flaw. The flaw can be demonstrated by Figure 1, point a > b, the script subtracts the gap between Pt. a and the "x" axis but this only adds the problem onto the end of Pt. b. How can you solve either the problem with this script or the problem in general?
function [zeroed_x,zeroed_y] = zero_xy_v2(x,y),
length_x = length(x); a = x(1); %first value of x b = x(length_x); %last value of x
% %Zero "X_axis" % zeroed_x = x;
% if a == b, % % if a == 0, % zeroed_x = x; % elseif a > 0, % zeroed_x = x  a; % else %a < 0 % zeroed_x = x + a; % end % % elseif ((a == 0) & (b > 0)), % zeroed_x = x  b; % % elseif ((a > 0) & (b == 0)), % zeroed_x = x  a; % % elseif ((a < 0) & (b > 0)), % zeroed_x = x  (b + a); % % elseif ((a > 0) & (b < 0)), % zeroed_x = x  (b + a); % % elseif ((a > 0) & (b > 0)), % if a > b, % zeroed_x = x  a; % else %b > a % zeroed_x = x  b; % end % % else %((a < 0) & (b < 0)) % % if a > b, % zeroed_x = x  a; % else %b < a % zeroed_x = x  b; % end % % end
% %Zero "Y_axis" % clear a b; length_y = length(y); a = y(1); %first value of y b = y(length_y); %last value of y
if a == b,
if a == 0, zeroed_y = y; elseif a > 0, zeroed_y = y  a; else %a < 0 zeroed_y = y + a; end
elseif ((a == 0) & (b > 0)), zeroed_y = y  b;
elseif ((a > 0) & (b == 0)), zeroed_y = y  a;
elseif ((a < 0) & (b > 0)), zeroed_y = y  (b + a);
elseif ((a > 0) & (b < 0)), zeroed_y = y  (b + a);
elseif ((a > 0) & (b > 0)), if a > b, %zeroed_y = y  a; % %This was my first effort to fix the problem on one part of the script  you can see why %I left it! dummy_y = y  a; length_dummy_y = length(y); a = y(1); %first value of y b = y(length_y); %last value of y
if b == 0, %To check and delete if part of the curve is below zero zeroed_y = zeroed_y; elseif b < 0 length_zeroed_y = length(zeroed_y); for k = 1:length_zeroed_y, if length_zeroed_y(k) > 0  length_zeroed_y(k) == 0, data(k) = length_zeroed_y(k); else data(k) = []; end zeroed_y = data; end %
else % b > 0
end
else %b > a zeroed_y = y  b; end
else %((a < 0) & (b < 0))
if a > b, zeroed_y = y  a; else %b < a zeroed_y = y  b; end
end
Any help will be appreciated.
Please look at the Figure 1 and read the question below:
y  * * * *  Load cell calibration data
In Figure 1 you have a set of load cell data. The thing is, the beginning and end points (Pt. and Pt. b) are above the "y" axis and away from the "x" axis i.e. they are not zeroed.
The following function was written to fix this problem, but it has an inherent flaw. The flaw can be demonstrated by Figure 1, point a > b, the script subtracts the gap between Pt. a and the "x" axis but this only adds the problem onto the end of Pt. b. How can you solve either the problem with this script or the problem in general?
function [zeroed_x,zeroed_y] = zero_xy_v2(x,y),
length_x = length(x); a = x(1); %first value of x b = x(length_x); %last value of x
% %Zero "X_axis" % zeroed_x = x;
% if a == b, % % if a == 0, % zeroed_x = x; % elseif a > 0, % zeroed_x = x  a; % else %a < 0 % zeroed_x = x + a; % end % % elseif ((a == 0) & (b > 0)), % zeroed_x = x  b; % % elseif ((a > 0) & (b == 0)), % zeroed_x = x  a; % % elseif ((a < 0) & (b > 0)), % zeroed_x = x  (b + a); % % elseif ((a > 0) & (b < 0)), % zeroed_x = x  (b + a); % % elseif ((a > 0) & (b > 0)), % if a > b, % zeroed_x = x  a; % else %b > a % zeroed_x = x  b; % end % % else %((a < 0) & (b < 0)) % % if a > b, % zeroed_x = x  a; % else %b < a % zeroed_x = x  b; % end % % end
% %Zero "Y_axis" % clear a b; length_y = length(y); a = y(1); %first value of y b = y(length_y); %last value of y
if a == b,
if a == 0, zeroed_y = y; elseif a > 0, zeroed_y = y  a; else %a < 0 zeroed_y = y + a; end
elseif ((a == 0) & (b > 0)), zeroed_y = y  b;
elseif ((a > 0) & (b == 0)), zeroed_y = y  a;
elseif ((a < 0) & (b > 0)), zeroed_y = y  (b + a);
elseif ((a > 0) & (b < 0)), zeroed_y = y  (b + a);
elseif ((a > 0) & (b > 0)), if a > b, %zeroed_y = y  a; % %This was my first effort to fix the problem on one part of the script  you can see why %I left it! dummy_y = y  a; length_dummy_y = length(y); a = y(1); %first value of y b = y(length_y); %last value of y
if b == 0, %To check and delete if part of the curve is below zero zeroed_y = zeroed_y; elseif b < 0 length_zeroed_y = length(zeroed_y); for k = 1:length_zeroed_y, if length_zeroed_y(k) > 0  length_zeroed_y(k) == 0, data(k) = length_zeroed_y(k); else data(k) = []; end zeroed_y = data; end %
else % b > 0
end
else %b > a zeroed_y = y  b; end
else %((a < 0) & (b < 0))
if a > b, zeroed_y = y  a; else %b < a zeroed_y = y  b; end
end
Any help will be appreciated.