Convert uint8 vector to float
27 views (last 30 days)
Show older comments
Hi All,
i have a .mf4-measurement data in uint8:
1×20 uint8 row vector
132 132 132 132 132 132 133 133 133 133 134 138 170 214 222 226 224 216 215 215
is there a way to convert it to these physical values (float)?
0.01 0.01 0.01 0.01 0.01 0.01 0.02 0.02 0.02 0.02 0.03 0.07 0.39 0.83 0.91 0.95 0.93 0.85 0.84 0.84
Thank u and kind regards,
2 Comments
Les Beckham
on 30 Jan 2023
Normally this would be as simple as converting the input data to double and multiplying by a scale factor. Your example values, however don't have a simple linear relationship between the input data and the example output data (see below).
Can you clarify how your example "physical values" were generated?
in = uint8([132 132 132 132 132 132 133 133 133 133 134 138 170 214 222 226 224 216 215 215])
out = [0.01 0.01 0.01 0.01 0.01 0.01 0.02 0.02 0.02 0.02 0.03 0.07 0.39 0.83 0.91 0.95 0.93 0.85 0.84 0.84]
SF = out./double(in)
plot(SF)
grid on
Accepted Answer
Star Strider
on 30 Jan 2023
Since you apparently know the mapping, one option is to simply calculate a linear regression (assuming that a linear relation exists) —
u = uint8([132 132 132 132 132 132 133 133 133 133 134 138 170 214 222 226 224 216 215 215]);
v = [0.01 0.01 0.01 0.01 0.01 0.01 0.02 0.02 0.02 0.02 0.03 0.07 0.39 0.83 0.91 0.95 0.93 0.85 0.84 0.84];
B = [132 1; 226 1] \ [0.01; 0.95] % Linear Regression
f = [double(u(:)) ones(size(u(:)))] * B;
figure
plot(double(u), v, '.', 'DisplayName','Data')
hold on
plot(double(u), f, '-', 'DisplayName','Linear Regression')
hold off
grid
xlabel('u')
ylabel('f')
legend('Location','N')
It would likely help to know what the data represent and what the actual conversion is. This approach is a guess that may not work on data other than those in the range of the ‘u’ vector.
.
2 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
