function [force_lin, idx]= MoBi_linearize_force(force_from_arduino, linearize, funz) %% the function brings the arudino voltage output onto a line (force applied should be linearly related to output value) % linearize = linspace(0, max_force, force_steps); if isempty(force_from_arduino) idx = 0; else idx = find(force_from_arduino<=funz, 1, 'first'); end % in case force_from_arduino is greater than any value from funz, idx = % length(funz) --> so whatever higher value, the output is always the last % idx of funz if isempty(idx) idx = length(funz) end force_lin = linearize(idx); end