Convert uint8 vector to float

조회 수: 27 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by