Why appears error message using functions like floor, mod and rem?

8 views (last 30 days)
I'm trying to make a script code in order to convert arabic number to roman numbers. I some cases, when I use functions to separate the quantity by thounsands, hundreds, tens, etc., error messages appear as the following:
>> floor(2780,1000)
??? Error using ==> floor
Too many input arguments.
The same occurs when I use mod or rem functions. So, what could be the writing error or argument type to this kind of error messages appears?
  2 Comments
Les Beckham
Les Beckham on 11 Mar 2018
Edited: Les Beckham on 11 Mar 2018
Did you, perhaps, mean the following?
floor(2780/1000)
The results of this would be 2.
Floor does not, as I recall, accept more than one argument, thus the error message. You can, of course, pass an array to floor but this is still just one argument.
Les Beckham
Les Beckham on 12 Mar 2018
Perhaps I should clarify that Matlab interprets commas inside of function calls as a separator between arguments. Thus, your original call to floor has two arguments (2780 and 1000), separated by the comma.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 11 Mar 2018
In MATLAB you cannot use commas as the thousands separator -- or as the decimal point either.
If there is a requirement that you accept numbers of that form, then you will need to enclose them in '' to make them character vectors, and then you will need to replace the comma with a period and ask MATLAB to convert the result to numeric form:
S = '2780,1000';
str2double(regexprep(S, ',', '.', 'once'))
Alternately, you can have the user enter a vector of three values, in which the first entry is the part before the decimal point, and the second entry is the part to go after the decimal point, and the third entry is the number of digits in the second part. For example,
S = [2780, 1000, 4]
and you would then do S(1) + S(2)/10^S(3)
The reason that you need the number of digits passed is that if you were to pass in
S = [2780, 01000]
as intended to imply 2780.01000 then MATLAB would not be able to tell the difference between that and S = [2780, 1000] implying 2780.1000 -- MATLAB cannot detect how many leading zeros were given in a decimal number.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!