What is wrong with my "if is integer" code

조회 수: 9 (최근 30일)
Michael  Kurniawan
Michael Kurniawan 2012년 10월 8일
I have a function roman= dectoroman(number) I want first to test out for if the number is an interger or not and I tried using the isinteger function but somehow its not working and not really sure why.
if isinteger(number)
x = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]; % Array of intergers (x)
y = {'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'};% array of strings equalling intergers above respectivly (y)
roman=[];%Instantiating
for ii = 1:numel(x)
number >= x(ii);
roman = [roman,repmat(y{ii},1,fix(number/x(ii)))];
number = rem(number,x(ii));
else
error('error')
end
end
end
wondering if there was anyway to test if its not an integer so i can just go if its to an integer ---> error end
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 8일
where is your if?
Walter Roberson
Walter Roberson 2012년 10월 8일
Azzi, the first line, "if isinteger(number)"

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 8일
편집: Azzi Abdelmalek 2012년 10월 8일
because
isinteger(1)=0 % for example
try
if fix(a)==a

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 10월 8일
A number is an integer if mod(number,1) == 0

카테고리

Help CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by