フィルターのクリア

scatter plot in matlab

1 回表示 (過去 30 日間)
Ying
Ying 2012 年 1 月 16 日
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!

採用された回答

the cyclist
the cyclist 2012 年 1 月 16 日
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 件のコメント
Ying
Ying 2012 年 1 月 16 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by