0

I am trying to run a random walk simulation and graphs it.

What i'm trying to get is to plot the first point of the graph, then offer the user an input box to guess whether the next point will go up or down, then show them the next point on the graph and so on.

I've made the code that runs the random walk but I don't know how to make it pause and allow for a user input.

Can anyone give me any ideas?

MBZ
  • 26,084
  • 47
  • 114
  • 191
  • Have you tried ANSWER = INPUTDLG(PROMPT,NAME) ? – jerad Dec 10 '12 at 20:28
  • @jerad Yeah ive used inputdlg to get a code that does the input part but i'm still having trouble working out how to get the code to plot one point and wait for this input, then plot the next – Kaye Macleod Dec 10 '12 at 20:53

1 Answers1

0

Here's some code that should get you started

N = 100;
y = rand(1,N);
x = 1:N;

figure;
h = stairs(x(1),y(1));
xlim( [0 100] );
ylim( [0 1] )
hold on;
for ii = 2:N    
    set(h, 'xdata', x(1:ii), 'ydata', y(1:ii))
    pause(0.5) % Pause line to demonstrate to yourself that it works as desired
    % You can replace it with inputdlg() to collect a user response instead
end
jerad
  • 2,028
  • 15
  • 16