I have some arrays of data in range [-1,1] and need to convert them to range [0,255] in Matlab. Either formula or code! (I checked Matlab functions but i could not find any function related to this conversion!)
Asked
Active
Viewed 620 times
-1
-
Please post what you have done so far – Ormoz Aug 25 '15 at 02:00
-
6You'll be looking at something like applying `x = (x + 1) * 255 / 2` to each element. Commenting since I know squat about Matlab but more than enough about math :-) – paxdiablo Aug 25 '15 at 02:05
-
2@paxdiablo - That's how you'd implement it in MATLAB :) – rayryeng Aug 25 '15 at 03:09
1 Answers
1
See this small piece of exmaple code.
n = 10;
a = 2*rand(1,n) - 1; % some random data in [-1,1]
b = 255/2*(a+1); % linear projection to [0,255]

wsdzbm
- 3,096
- 3
- 25
- 28