program simulate tossing a coin

Hello everybody please anyone answer me because I want to run this program but some error occurs,How can I solve this problem
N=input('Enter the number of simulations:')
for k=1:N
rand_number=rand;
if random_number<0.5
random_number(k,1)=1;
else
random_number(k,1)=0;
end
end
fprintf('\n')

 Respuesta aceptada

Walter Roberson
Walter Roberson el 7 de Abr. de 2011

0 votos

You assign to rand_number, but on the next line you test random_number

6 comentarios

reem
reem el 7 de Abr. de 2011
Thank you so much Walter
but I rewrite random_number,when I want to run
this command occur
??? Attempt to execute SCRIPT rand as a function:
C:\Users\N\Documents\MATLAB\rand.m
Error in ==> num1 at 3
random_number=rand;
reem
reem el 7 de Abr. de 2011
I think the problem in rand function
but I want to generate random variable and by RAND we can generate random variable
so what is the problem here
Walter Roberson
Walter Roberson el 7 de Abr. de 2011
You have accidentally named a file "rand.m", which conflicts with the built-in rand function. You will have to rename C:\Users\N\Documents\MATLAB\rand.m to something else.
reem
reem el 7 de Abr. de 2011
Dear Walter,
I changed the name and when I want to running ,there is no any running for program
only this result appear
Enter the number of simulations:33
N =
33
Walter Roberson
Walter Roberson el 7 de Abr. de 2011
Yup. That's the only thing you request to print out in the code, other than the newline at the end. Your program is now functioning to the limits of all of the requirements you have indicated to us.
The variable name is corrected and the program no longer gives an error, so the matter is solved as far as the initial question is concerned.
You may perhaps now wish to go back and edit the question in order to include an explanation of what you need the program to _do_ and what it does instead, and to include an updated version of your code.
reem
reem el 7 de Abr. de 2011
Thank you Walter for your fast response
Now,I solved the question
once again thank you so so much

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 7 de Abr. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by