skip the value in for-loop
Mostrar comentarios más antiguos
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.
Respuestas (2)
David Hill
el 5 de Abr. de 2020
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 comentarios
Kapil Gupta
el 5 de Abr. de 2020
Editada: Kapil Gupta
el 5 de Abr. de 2020
Kapil Gupta
el 5 de Abr. de 2020
Editada: Kapil Gupta
el 5 de Abr. de 2020
David Hill
el 5 de Abr. de 2020
I don't understand what you are saying. Please explain more. What do you want your output to be?
Kapil Gupta
el 5 de Abr. de 2020
David Hill
el 5 de Abr. de 2020
Show me what you want for your output (i=2:4)
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 comentarios
Kapil Gupta
el 5 de Abr. de 2020
Editada: Kapil Gupta
el 5 de Abr. de 2020
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.
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!