How to index with engineering notation
13 views (last 30 days)
Show older comments
Keiland Cooper
on 15 Mar 2017
Edited: John D'Errico
on 15 Mar 2017
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 Comment
Adam
on 15 Mar 2017
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.
Accepted Answer
John D'Errico
on 15 Mar 2017
Edited: John D'Errico
on 15 Mar 2017
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 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!