필터 지우기
필터 지우기

format short and format long

조회 수: 21 (최근 30일)
Harel Harel Shattenstein
Harel Harel Shattenstein 2016년 12월 30일
편집: Stephen23 2016년 12월 30일
I need to find the relative error between 2 variable, the one in format short and the other in format long. How can I take the same variable, once in short and once in long so I can subtract the two?
  댓글 수: 1
Stephen23
Stephen23 2016년 12월 30일
편집: Stephen23 2016년 12월 30일
This question makes no sense. Numeric data is stored in an array of any of the numeric data types (e.g. single, double, uint32, etc), and is displayed in the command window using the currently specified format (e.g. longg, bank, etc). The format has nothing to do with the precision of calculations, nor anything to do with the precision of stored data. Exactly as the documentation clearly states, format is only relevant to the displaying of data, so the statement "I take the same variable, once in short and once in long so I can subtract the two" is totally meaningless.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2016년 12월 30일
If you have one variable that is single precision and one that is double precision, you can perform your calculation with them as you normally would. The result will be single precision.
According to the documentation on Floating-Point Numbers, specifically Single-Precision Operations:
  • You can perform basic arithmetic operations with single and any of the following other classes. The result is always single:
single
double
char
logical

추가 답변 (1개)

John D'Errico
John D'Errico 2016년 12월 30일
I think perhaps you misunderstand. Format short does not cause a variable to be stored in any format, nor does format long.
The numbers were always stored in the same precision (usually double precision, unless you specified something else like single.)
So the format command is strictly a tool to change how a number as displayed.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by