I have a function that I would like to take input for but only when the user wants to. For example if i have this code:
figure
amplitude = 10;
tic
i = 1;
while(1)
time = toc;
values(i) = amplitude*sin(time);
times(i) = time;
plot(times, values)
drawnow
i = i+1;
end
You will get a continually plotting sine wave (like a lame movie). What I want to do is allow the user to change the amplitude of the wave at any time. That is the program will continue to run but if the user types in 20 and Enter then the amplitude variable can be changed and the sine wave will change amplitude in the movie. Any pointers on how to achieve this?
It is probably best to do it with a GUI as mentioned, but if you just want something in the console here is what I can offer:
A script that periodically asks the user to input an amplitude and then continues the ‘movie’ with this amplitude. It can easily be expanded to allow the user to decide when he will be asked to input the next amplitude change.
Now this will run for a while and then ask you to input the next amplitude. Note that you can actually give multiple commands at once.
This will let the next amplitude be 20 and the one after that 1. Note that the upward arrow key is your friend here.