Convert uint8 vector to float

20 ビュー (過去 30 日間)
hohohihi
hohohihi 2023 年 1 月 30 日
コメント済み: Star Strider 2023 年 3 月 7 日
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 件のコメント
Les Beckham
Les Beckham 2023 年 1 月 30 日
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 2023 年 1 月 30 日
編集済み: hohohihi 2023 年 1 月 30 日
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,

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2023 年 1 月 30 日
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 件のコメント
hohohihi
hohohihi 2023 年 3 月 7 日
Very good idea, I'll check few of measurement data to confirm the linear relation.
Thank you Star!! :-)
Star Strider
Star Strider 2023 年 3 月 7 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by