Matlab - ayuda ejercicio

 
Vista:
sin imagen de perfil

ayuda ejercicio

Publicado por mana (3 intervenciones) el 22/10/2017 13:47:21
hola a todos,
tengo que hacer unos ejercicios con mat lab y no consigo hacer este, alguien me puede echar una mano:

if-statement: Write a short program using the if statement and the rand command,
that generates a uniform random number and stores it in r, then if r<0.5, set n=0,
otherwise set n=1. Finally, it displays the values of r and n (so that you can check if it is
working properly). Save the script as "Stepscript.m" in your working directory and launch

yo escribo

>> if r<0.5
n=0
elseif r>0.5
n=1
y me da error
diciendo q n es undefined near line 1 column 4

cualquier ayuda sera bien recibida
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

ayuda ejercicio

Publicado por nana (3 intervenciones) el 22/10/2017 16:04:58
lo he repetido y me sale r=0.53183
eso es correcto tambien?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

ayuda ejercicio

Publicado por mana (3 intervenciones) el 22/10/2017 16:28:25
muchas gracias, ya entiendo que es aleatorio,
en la segunda parte me dicen que:
for-statement: include the previous lines of program within a for-loop with index k
ranging from 1 to 10: store the random numbers in r(k) and the integers in n(k), then display
the resulting r and n vectors.
hago lo siguiente pero no se me despliegan los resultados
for k=10:1
r(k)
n(k)
end
ans = 0.50031
ans=1
al dar enter no se tendrian que desplegar todos los resultados??

Y despues tengo que
add the line mx=[r;n], and a line using the save command to save the variables r,n,mx in output.dat. Open such
file and look at the way the information is stored.

y eso no seria solo hacer
r=
n=
mx=
o no lo estoy entendiendo?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar