forked from DThornz/Hemodynamic-Calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremap.m
51 lines (51 loc) · 1.12 KB
/
remap.m
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function y = remap(b,ac,xz)
%REMAP Remap numerical values from range [a c] to range [x z].
%
% -------------
% INPUT
% -------------
% b - input scalar, vector, matrix
% ac - source range: 1-by-2 vector, a <= b <= c
% xz - target range: 1-by-2 vector, x <= y <= z
%
% -------------
% OUTPUT
% -------------
% y - output vector, remapped from range ac to xz
%
% -------------
% ALGORITHM
% -------------
% Formula to remap values comprised in the range [a c]
% to the range [x z] (b is the original value, y the target value):
%
% y = (b - a) * (z - x) / (c - a) + x
%
% -------------
% EXAMPLE
% -------------
% remap(5,[0 10],[0 1]) % = 0.5
% remap(128,[0 255],[0 1]) % = 0.502
% X = magic(3)
% remap(X,[min(min(X)) max(max(X))],[0 1])
%
% -------------
% TODO
% -------------
% Make this work for all matlab data classes.
%
% -------------
% LOG
% -------------
% 2015.12.07 - [new] transformed script to function
% 2010.10.11 - creation
%
% -------------
% CREDITS
% -------------
% Vlad Atanasiu, [email protected], http://alum.mit.edu/www/atanasiu/
a = ac(1);
c = ac(2);
x = xz(1);
z = xz(2);
y = (b - a) * (z - x) / (c - a) + x;