필터 지우기
필터 지우기

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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by