a = 27;
c = 11;
m = 54;
x(1)=2;
for i=2:25
x(i) = (mod(a * x(i-1)+c ,m))
end
here i want to skip the first value x(1)=2 to print in each iteration.
so please guide me how can i skip this value in output.

답변 (2개)

David Hill
David Hill 2020년 4월 5일

0 개 추천

a = 27;
c = 11;
m = 54;
x(1)=2;
for i=2:25
x(i) = (mod(a * x(i-1)+c ,m))
end
x(2:end)

댓글 수: 5

Kapil Gupta
Kapil Gupta 2020년 4월 5일
편집: Kapil Gupta 2020년 4월 5일
a = 27;
c = 11;
m = 54;
for i=2:25
x(1)=2;
x(i) = (mod(a * x(i-1)+c ,m))
R(i) = x(i)/m;
if x(i) == x(1)
fprintf('%.2f\n',i-1)
break
end
end
x(2:end)
this is problem i ihave an another condition but it not fulfil by your code.
Kapil Gupta
Kapil Gupta 2020년 4월 5일
편집: Kapil Gupta 2020년 4월 5일
i want to skip the x=2 in each iteration.
and from my code i received output after each iteration that is too long.so i need a single array output please suggest me.
David Hill
David Hill 2020년 4월 5일
I don't understand what you are saying. Please explain more. What do you want your output to be?
Kapil Gupta
Kapil Gupta 2020년 4월 5일
i want to skip first element from each output after each iteration.and follow the loop with if condition and print a single output for x(i) and R(i).now i think you may understand my problem.
David Hill
David Hill 2020년 4월 5일
Show me what you want for your output (i=2:4)

댓글을 달려면 로그인하십시오.

dpb
dpb 2020년 4월 5일
편집: dpb 2020년 4월 6일

0 개 추천

AMENDED:
Probably simplest is just
a = 27;
c = 11;
m = 54;
x(1)=2;
for i=2:25
x(i) = (mod(a * x(i-1)+c ,m));
end
x=x(2:end);
maybe? Just guessing; we can't tell what it is that you really want, unfortunately.

댓글 수: 2

Kapil Gupta
Kapil Gupta 2020년 4월 5일
편집: Kapil Gupta 2020년 4월 5일
In your answer if condition is not fulfil.
dpb
dpb 2020년 4월 6일
편집: dpb 2020년 4월 6일
What "if" is that??? No if's and's or but's in the question...just the wish to not display the "2" at the begining of each x vector.
The only If is that if we can't understand the question/desired output clearly we can't solve the problem.
Show explicitly what the specific output expected should be.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2020년 4월 5일

편집:

dpb
2020년 4월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by