Converting a fraction into a floating number
15 ビュー (過去 30 日間)
古いコメントを表示
Hi, I want to simply convert a fraction into a float. When I checked with the help, it seems really simple. To convert 2/5 into a float, it seems like I just need to type float(2/5). But, when I do that, I have for response :Error using float (line 46) The input argument to float was not a supported type. The only recognized input character vectors are 'single' and 'double'. The input type was 'double'. Can someone explain me that?
5 件のコメント
Walter Roberson
2018 年 1 月 30 日
John: float() is a legacy Simulink Fixed Point function. https://www.mathworks.com/help/simulink/slref/float.html
John D'Errico
2018 年 1 月 30 日
編集済み: Walter Roberson
2023 年 12 月 15 日
No. The examples given by Samuel are NOT consistent with the use of float as it is seen in the Simulink docs. However, they ARE consistent with the examples shown in the MuPAD documentation. That is why I talked about MuPAD. In fact, if I read the examples shown for the MuPAD float, we find very coincidentally these examples:
float(17), float(PI/7 + I/4), float(4^(1/3) + sin(7))
As copied directly out of this link:
回答 (3 件)
John D'Errico
2018 年 1 月 30 日
No. There is no need to use float.
x = 2/5
x =
0.4
whos x
Name Size Bytes Class Attributes
x 1x1 8 double
x is automatically a floating point number, of class double.
Cyrus Azizzadeh
2021 年 12 月 22 日
If I have an equation like (256753367864*t)/(46897532469) How can I convert that to float?
6 件のコメント
Walter Roberson
2021 年 12 月 23 日
See https://www.mathworks.com/matlabcentral/answers/337896-odd-r-n-output-from-symbolic-multiplication#answer_265002 and note the comment about TEXTWIDTH
This is an approach to get some readable representation of the result, not to get the result in MATLAB form. The result will be in the internal MuPAD language
参考
カテゴリ
Help Center および File Exchange で Special Values についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!