Effacer les filtres
Effacer les filtres

scatter plot in matlab

1 vue (au cours des 30 derniers jours)
Ying
Ying le 16 Jan 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!

Réponse acceptée

the cyclist
the cyclist le 16 Jan 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 commentaire
Ying
Ying le 16 Jan 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by