How to index with engineering notation

조회 수: 13 (최근 30일)
Keiland Cooper
Keiland Cooper 2017년 3월 15일
편집: John D'Errico 2017년 3월 15일
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
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
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개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by