Convert single to double
68 ビュー (過去 30 日間)
古いコメントを表示
Ana Gonçalves
2022 年 10 月 27 日
編集済み: Frederic Rudawski
2022 年 10 月 27 日
I have 1x18007 single, and it has a certain range (which is not the real range), and I need to convert it to double, to get the actual values.
PS.: typecast doesn't work.
>> a = typecast(driverAppliedTorqueAtSteeringWheel, 'double');
Error using typecast
The first input must contain a multiple of 2 elements to convert from single (32 bits) to
double (64 bits).
1 件のコメント
James Tursa
2022 年 10 月 27 日
編集済み: James Tursa
2022 年 10 月 27 日
"... I need to convert it to double, to get the actual values ..."
This doesn't make any sense to me. Converting singles to doubles will result in exactly the same value since doubles can represent every single exactly, just in a different bit representation format. Please explain what you mean by "actual values." Maybe you can give a few examples of single values and what double values you think they should be converted to.
採用された回答
Frederic Rudawski
2022 年 10 月 27 日
編集済み: Frederic Rudawski
2022 年 10 月 27 日
My first guess would be:
a = double(driverAppliedTorqueAtSteeringWheel)
But you probably have to adjust the range yourself.
EDIT:
The problem with typecast is, that you need 2 singles to create one double, so you need to fill the missing information with addiditional singles, e.g.:
data = single([1;2;3;4;5])
b = single(zeros(size(data)));
M = [b data]';
newdata = M(:)
a = typecast(newdata,'double')
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Numeric Types についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!