Skip to content

Instantly share code, notes, and snippets.

@hamaluik
Created January 15, 2016 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamaluik/9554c62876d386591aab to your computer and use it in GitHub Desktop.
Save hamaluik/9554c62876d386591aab to your computer and use it in GitHub Desktop.
function [ varargout ] = trimzeros( varargin )
%TRIMZEROS Removes trailing "zero" datapoints from the input vectors
% At the end of the `emg` array are expected to be a series of 0.0 values which
% cause problems for data analysis. This function will remove those zeros from the
% input columns. Call this function using either:
% >> [ t, emg ] = trimzeros(t, emg);
% or:
% >> [ t, emg, force ] = trimzeros(t, emg, force);
if (nargin < 2) || (nargin > 3)
error('Please call this function with 2 or 3 arguments in the order: t, emg, force!');
end
if nargin ~= nargout
error('Please call this function with the same number of outputs as inputs!');
end
% find the first ending 0
i = length(varargin{2});
for k = i:-1:1
if varargin{2}(k) ~= 0
i = k;
break;
end
end
% found the first starting 0, it's at index: i + 1
% trim the arrays!
for k = 1:nargout
varargout{k} = varargin{k}(1:i);
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment