Borrar filtros
Borrar filtros

scatter plot in matlab

1 visualización (últimos 30 días)
Ying
Ying el 16 de En. de 2012
Hi,
I'm new to Matlab. And I need to write a congruential random number generator without using RAND().And then plot the Ui vs Ui+1
My code is:
>> syms m x a u z;
>> x=1;
>> a=16807;
>> m=2^31-1;
>> for i=1:10
y=a*x
x=mod(y,m)
u(i)=x/m %store u value
end;
>> for i=1:10
end;
>> scatter(u(i+1),u(i))
I got this"Index exceeds matrix dimensions." error message.
Anyone who can tell me how to plot my ui vs ui+1? I think my code does generate correct ui values.
I'm using it for tomrrow's class.
Thanks very much!

Respuesta aceptada

the cyclist
the cyclist el 16 de En. de 2012
I think you should be able to do the scatter plot you want using:
scatter(u(2:end),u(1:end-1))
The reason you got the error you did is that i is equal to 10, so in the scatter command you are trying to access the ( i+1 )th element of u. But u is only a 10-element vector, of course.
  1 comentario
Ying
Ying el 16 de En. de 2012
the cyclist,
Thanks a lot for answering my question! This looks identical to my excel scatter output. I think this should be fine for my class.
Ying

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by