What is wrong with my "if is integer" code
10 ビュー (過去 30 日間)
古いコメントを表示
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
2012 年 10 月 8 日
編集済み: Azzi Abdelmalek
2012 年 10 月 8 日
because
isinteger(1)=0 % for example
try
if fix(a)==a
0 件のコメント
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Particle & Nuclear Physics についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!