Weird problem with fix.

조회 수: 2 (최근 30일)
MSP
MSP 2017년 7월 22일
편집: Star Strider 2017년 7월 22일
Guys do you know why fix on matlab 2017a is behaving weirdly. Pls have a look on the attached pic.This is not photoshopped.

답변 (2개)

Matt J
Matt J 2017년 7월 22일
편집: Matt J 2017년 7월 22일
Because out(1,3) is only displayed to four decimal places, it is possible that it's value is actually 3.99999999999999999 or something like that. Because it's value is slightly less than 4, fix() returns 3 for that entry.

Star Strider
Star Strider 2017년 7월 22일
편집: Star Strider 2017년 7월 22일
The format displays the value rounded to the nearest integer. The fix function rounds toward zero (for both positive and negative numbers).
Example
format long g
R1C2 = 3.9999999999
format short g
Q1 = R1C2
Q2 = fix(R1C2)
R1C2 =
3.9999999999
Q1 =
4
Q2 =
3
————————————————————
EDIT Clarified explanation.

카테고리

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