-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapfun.m
More file actions
30 lines (29 loc) · 895 Bytes
/
mapfun.m
File metadata and controls
30 lines (29 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
% This function is a copy of the "map" function used in Arduino code.
% It takes an input value mapped from a min and max possible value and
% scales it to a desired output min and max.
%
% [output] = mapfun(value,fromLow,fromHigh,toLow,toHigh)
% value: can be a scalar entry or a matrix of values
% fromLow: lowest possible input value
% fromHigh: highest possible input value
% toLow: lowest desired output value
% toHigh: highest possible output value
% [output]: output matrix of same size as value
%
% examples:
% output = mapfun(-.3,-1,1,0,5)
% output =
%
% 1.7500
%
% output = mapfun([-1 1 -.5 .5],-1,1,0,5)
% output =
%
% 0 5.0000 1.2500 3.7500
%
% Created by David Coventry on 1/19/2017
function output = mapfun(value,fromLow,fromHigh,toLow,toHigh)
narginchk(5,5)
nargoutchk(0,1)
output = (value - fromLow) .* (toHigh - toLow) ./ (fromHigh - fromLow) + toLow;
end