How to index with engineering notation
13 ビュー (過去 30 日間)
古いコメントを表示
I have an array of values that are stored in engineering notation. I want to use them as indices for another array. However, matlab will not let me index in this notation. I had tried using format to convert the data, however, this rounded the end of the numbers. I need a way to either convert the numbers while maintaining accuracy, or indexing with them in their current notation somehow.
1 件のコメント
Adam
2017 年 3 月 15 日
Can you give an example? The notation in which you view a variable in the variable editor or command line has nothing to do with how it can be used in calculations.
採用された回答
John D'Errico
2017 年 3 月 15 日
編集済み: John D'Errico
2017 年 3 月 15 日
I think you are mistaken in some way. Numbers are NOT stored in engineering notation in MATLAB. They can be displayed that way. They are stored in a standard IEEE form that uses a binary mantissa with 52 bits of precision.
For example, the number 1.23e5 is EXACTLY an integer as it is stored in MATLAB.
sprintf('%0.55f',1.23e5)
ans =
123000.0000000000000000000000000000000000000000000000000000000
You can feel free to use the number as an index.
A(1.23e5) = 1;
If that number is too large to store as a flint (floating point integer) in MATLAB, then it must be larger than 2^53. That would be wildly too large of an array to create in MATLAB, unless you are VERY well funded for memory. Does your computer make Skynet seem weak and puny by comparison?
If your number is not in fact an integer, then of course indexing will fail!
A(1.234567e5) = 1;
Subscript indices must either be real positive integers or logicals.
However, fix, round, ceil or floor will all work, depending upon how you might want to do the mapping to an integer.
A(fix(1.234567e5)) = 1;
(Note that format does NOT convert data into another representation, as an integer. Format is purely for display purposes.)
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!