MoBi_linearize_force.m 637 B

12345678910111213141516171819202122232425
  1. function [force_lin, idx]= MoBi_linearize_force(force_from_arduino, linearize, funz)
  2. %% the function brings the arudino voltage output onto a line (force applied should be linearly related to output value)
  3. % linearize = linspace(0, max_force, force_steps);
  4. if isempty(force_from_arduino)
  5. idx = 0;
  6. else
  7. idx = find(force_from_arduino<=funz, 1, 'first');
  8. end
  9. % in case force_from_arduino is greater than any value from funz, idx =
  10. % length(funz) --> so whatever higher value, the output is always the last
  11. % idx of funz
  12. if isempty(idx)
  13. idx = length(funz)
  14. end
  15. force_lin = linearize(idx);
  16. end