Convert uint8 vector to float

110 vues (au cours des 30 derniers jours)
hohohihi
hohohihi le 30 Jan 2023
Commenté : Star Strider le 7 Mar 2023
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 commentaires
Les Beckham
Les Beckham le 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])
in = 1×20
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]
out = 1×20
0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0200 0.0200 0.0200 0.0200 0.0300 0.0700 0.3900 0.8300 0.9100 0.9500 0.9300 0.8500 0.8400 0.8400
SF = out./double(in)
SF = 1×20
0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0002 0.0002 0.0002 0.0002 0.0002 0.0005 0.0023 0.0039 0.0041 0.0042 0.0042 0.0039 0.0039 0.0039
plot(SF)
grid on
hohohihi
hohohihi le 30 Jan 2023
Modifié(e) : hohohihi le 30 Jan 2023
HI Les,
thank u for ur answer.
Thats my problem, i've tried many conversion, also with im2double, but unfortunately it did not work.
I use ETAS-MDA Tool to analyze my .mf4-measurement, on that tool i do have 3 options to view my data:
  • Physical Value
  • HEX
  • and Decimal (RAW)
When i set the dataview to physical value, i got that values (0.01 0.01 0.01 0.01 ...).
When i set the datareview to decimal (RAW), i got the uint8 values (132 132 132 132...)
it happened too, when i imported my mf4-measurement to MATLAB by mdf-reader, thats why i'm trying to find a way to get the physical values by converting..
Kind regards,

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 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
B = 2×1
0.0100 -1.3100
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 commentaires
hohohihi
hohohihi le 7 Mar 2023
Very good idea, I'll check few of measurement data to confirm the linear relation.
Thank you Star!! :-)
Star Strider
Star Strider le 7 Mar 2023
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by