MATLAB: Issue with random function

looprandom

Hello guys,
I have an issue with the function RANDOM that is not producing random numbers as it should. Here is the code:
for j=1:25
random(j, 1)=rand*(time(j, 1)/2);
random(j, 2)=rand*(time(j, 1)/2);
random(j, 3)=rand*(time(j, 1)/2);
end
If I input this in the command window and assign a value to "time", it works, but in my script, I am always getting the same number on every column! I tried to debug it with breakpoints, but I cannot see why from one line to the other, the "rand" function cannot produce random numbers.
Also inside this for loop, I then have different assignments to the time matrix, eg: time(j, 2) or time(j, 3) so it is not ok to just generate random numbers. I have to connect them with specific entries of the time matrix.

Best Answer

I found the issue to the problem. I named a variable "rand" earlier in my code. Matlab didn't give me any information this would in fact replace the function RAND by the value of the variable rand I declared, so effectively the RAND function was not producing random numbers anymore!
I didn't know using a variable called rand would overwrite Matlab's RAND function. Good to know, problem solved! :-)