Why do I keep on getting "Not Enough Inputs" for an If statement in a function

Hello, I keep on getting these two errors in my Matlab code
>>PartOne
Please enter a number between 0 & 9999:
42
num =
42
Not enough input arguments.
Error in Big (line 6)
if (num <10000 )
Error in PartOne (line 11)
sum = (Big - Small);
>>
Heres my script code:
num = input ( 'Please enter a number between 0 & 9999: \n' )
count =0;
sum = num;
converge = false;
while num >= 0 & num <= 10000 %Postive value between 1 and 4 digits.
for I=1:1:8
count =+ 1 ;
toBig = Big(sum);
toSmall = Small(sum);
sum = (Big - Small);
if sum==6174
converge = true;
break;
end
end
end
if converge
fprintf(' %f Converges and needs %f iterations', num ,count )
elseif converge == false
fprintf(' %f does not converge.', num)
end
And my function codes:
function SmB = Big(num)
%Small to big
NUMARR= zeros(1,4);
if (num <10000 )
Fourth = mod(num,10);
Third = ( mod(num,100) - (mod(num,10)))/10;
Second = ( mod(num,1000) - (mod(num,100)) )/100;
First = ( mod(num,10000) - (mod(num,1000)) )/1000;
elseif (num<1000) % 3 digit number
First = 0;
Fourth = mod(num,10);
Third = ( mod(num,100) - (mod(num,10)))/10;
Second = ( mod(num,1000) - (mod(num,100)) )/100;
elseif( num<100) %2 digit
First = 0;
Second = 0;
Fourth = mod(num,10);
Third = ( mod(num,100) - (mod(num,10)))/10;
elseif (num<10) %1 digit
First = 0;
Second = 0;
Third = 0;
Fourth = mod(num,10);
end
NUMARR(1,1) = First;
NUMARR(1,2) = Second;
NUMARR(1,3) = Third;
NUMARR(1,4) = Fourth;
sort(NUMARR);
SmB = (NUMARR(1,1)*1000) + (NUMARR(1,2)*100) + (NUMARR(1,3)*10) + (NUMARR(1,4)) ;
end
function BiS = Small(num)
%Big to Small
NUMARR= zeros(1,4);
if num<(10000) %4 Digit Number
Fourth = mod(num,10);
Third = ( mod(num,100) - (mod(num,10)))/10;
Second = ( mod(num,1000) - (mod(num,100)) )/100;
First = ( mod(num,10000) - (mod(num,1000)) )/1000;
elseif (num<1000) % 3 digit number
First = 0;
Fourth = mod(num,10);
Third = ( mod(num,100) - (mod(num,10)))/10;
Second = ( mod(num,1000) - (mod(num,100)) )/100;
elseif (num<100) %2 digit
First = 0;
Second = 0;
Fourth = mod(num,10);
Third = ( mod(num,100) - (mod(num,10)))/10;
elseif (num<10) %1 digit
First = 0;
Second = 0;
Third = 0;
Fourth = mod(num,10);
end
NUMARR(1,1) = First;
NUMARR(1,2) = Second;
NUMARR(1,3) = Third;
NUMARR(1,4) = Fourth;
sort(NUMARR, 'descend');
BiS = (NUMARR(1,1)*1000) + (NUMARR(1,2)*100) + (NUMARR(1,3)*10) + (NUMARR(1,4)) ;
end

 採用された回答

Adam Danz
Adam Danz 2019 年 4 月 29 日
編集済み: Adam Danz 2019 年 4 月 29 日
'Big' is a function. When you call this line
sum = (Big - Small);
you're calling your function Big() without any inputs. The same is true for 'Small()'.
You haven't provided the 'Big' function but that's probably what's going on assuming it's similar to the Small() function.
By the way, your variable names need some work. "Sum" should never be a variable name since the sum() function is a common function. In generaly, variable names and function names should be descriptive.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLabels and Annotations についてさらに検索

製品

リリース

R2019a

質問済み:

2019 年 4 月 29 日

編集済み:

2019 年 4 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by