Created
January 15, 2016 16:49
-
-
Save hamaluik/9554c62876d386591aab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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