Randi worked in a program I ran 5 weeks ago, today it doesn't-what gives?

Dear all,
I had a perfectly-functioning program that used this line:
c = randi([1,n],mn,1)
where n and mn are integers. I've re-opened the program to do a monte carlo simulation, and all I get is an error message stating:
Error using randi
Too many input arguments.
Mind you, I haven't changed a coma in the program. I'm just running it again to re-acquaint myself with had I had done.
Any thoughts?

 Accepted Answer

Don't write an m-file that is named randi, at least, if you will ever want to use randi. Try this:
which randi -all
If there is a function named randi that you created, then you did exactly that.
In general, avoid naming functions with existing function names. Check BEFORE you create that file.

6 Comments

Fede C 2018 London's comment mistakenly posted as an answer moved here:
Thanks for your email. I didn't explain myself well, so apologies over my lack of clarity. I don't have a script named randi, or a function with that name. It's just one line in my script.
Have you run the command that John tell you to run and what was its output?
Also, give us the full text of the error message (everything in red)
I did, yes. The first four lines below are the error messages (in red).
Error using randi
Too many input arguments.
Error in COHforMC (line 181)
c = randi([1,n],mn,1)
>> which randi -all
C:\Users\federico\Documents\MATLAB\mvgc_v1.0\utils\legacy\randi\randi.m
C:\Program Files\MATLAB\R2018b\toolbox\matlab\randfun\@RandStream\randi.m % RandStream method
C:\Program Files\MATLAB\R2018b\toolbox\distcomp\parallel\@codistributed\randi.m % codistributed method
C:\Program Files\MATLAB\R2018b\toolbox\distcomp\parallel\@codistributor1d\randi.m % codistributor1d method
C:\Program Files\MATLAB\R2018b\toolbox\distcomp\parallel\@codistributor2dbc\randi.m % codistributor2dbc method
C:\Program Files\MATLAB\R2018b\toolbox\distcomp\parallel\@distributed\randi.m % distributed method
C:\Program Files\MATLAB\R2018b\toolbox\distcomp\gpu\@gpuArray\randi.m % gpuArray method
built-in (C:\Program Files\MATLAB\R2018b\toolbox\matlab\randfun\randi) % Shadowed
Regardless of what you think you have done, if you get an error message that tells you there are too many inpout arguments for randi, then you have done somethign to randi. So you need to tell us what the result of the which command is. Telling us the complete error message will also help. Because that will let us track down what you did.
You don't need to have changed ANYTHING in that particular program. You only need to have CREATED and saved a file named randi.
" I don't have a script named randi, or a function with that name."
MATLAB disagrees with you:
C:\Users\federico\Documents\MATLAB\mvgc_v1.0\utils\legacy\randi\randi.m
It appears you're using this toolbox. Delete it or at least remove it from your path since it shadows built-in functions randi and rng and maybe more.
I would also recommend getting in touch with them to complain about that shadowing.

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!