I want my code to run continuously.
3 visualizzazioni (ultimi 30 giorni)
In a .m file I wrote the following. g = randi(3,1)
When I press f5 and run it. It will give me a random number from 1 to 3. However, it will not change.
g will forever be 1, what can I do that so that when I run my code, each time i type "g" it will give me a different random number from 1 to 3?
Walter Roberson il 5 Dic 2013
You are not defining a function, you are defining a variable. You can use this, provided you save it in the file "g.m"
function r = g
r = randi(3,1);
You cannot use this at the MATLAB command prompt, you must write it to a file.