How to separate integers and decimal numbers from given values?

조회 수: 17 (최근 30일)
Omer Javaid m
Omer Javaid m 2016년 7월 21일
답변: Star Strider 2016년 7월 21일
How to separate integers and decimal numbers from given values?
  댓글 수: 1
Adam
Adam 2016년 7월 21일
Can you give an example. I don't understand what you are asking.

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

답변 (3개)

Star Strider
Star Strider 2016년 7월 21일
If you want to separate the value to the left and right of the decimal point, this works:
LD_RD = @(x) [fix(x) rem(x,1)]; % Separates Numbers Left & Right Of The Decimal
v = [1 2.1 pi 10 8.125]';
Result = [v LD_RD(v)]
Result =
1 1 0
2.1 2 0.1
3.1416 3 0.14159
10 10 0
8.125 8 0.125

Stephen23
Stephen23 2016년 7월 21일
편집: Stephen23 2016년 7월 21일
>> V = [1,2.3,4,5.6,7.8,9]; % fake data
>> X = fix(V)==V;
>> V(X) % integer values
ans =
1 4 9
>> V(~X) % values with decimal fraction
ans =
2.3000 5.6000 7.8000

KSSV
KSSV 2016년 7월 21일
편집: KSSV 2016년 7월 21일
number=1.77;
integ=floor(number);
fract=number-integ;
  댓글 수: 1
Stephen23
Stephen23 2016년 7월 21일
@Dr. Siva Srinivas Kolukula: if you use fix then this also works for negative values:
>> N = -1.2;
>> I = fix(N)
I = -1
>> F = N-I
F = -0.20000

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

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by