From: Brie Howley on
Is there a way to run a while loop that will go on indefinitely until
a user input (keyboard command) tells it to stop? I can start the
while loop with a user command but I can't figure out how to stop it
and go on to the next part of the program.

command = input('[Enter] to run, [Q] to quit: ');
r=1;
while isempty(command)==1
r=r+1;
end
From: chandra prakash on
hi
i think you have to take the user input once you entered into the
while loop.In your case after taking the user input it is entering
into infinite while loop.So, you have to use something like do-while
loop.
Enter into loop, check for user input,if no input (Quit) then
continue loop....something like this
i hope you got the idea.
Brie Howley wrote:
>
>
> Is there a way to run a while loop that will go on indefinitely
> until
> a user input (keyboard command) tells it to stop? I can start the
> while loop with a user command but I can't figure out how to stop
> it
> and go on to the next part of the program.
>
> command = input('[Enter] to run, [Q] to quit: ');
> r=1;
> while isempty(command)==1
> r=r+1;
> end
From: Brie on
I guess what I need to know is if there is a command that checks for
user input without stopping and waiting. Timing is an issue so I
need the loop to continue uninterrupted if there isn't any command to
stop it.

Brie Howley wrote:
>
>
> Is there a way to run a while loop that will go on indefinitely
> until
> a user input (keyboard command) tells it to stop? I can start the
> while loop with a user command but I can't figure out how to stop
> it
> and go on to the next part of the program.
>
> command = input('[Enter] to run, [Q] to quit: ');
> r=1;
> while isempty(command)==1
> r=r+1;
> end
From: jos on
Brie wrote:
>
>
> I guess what I need to know is if there is a command that checks
> for
> user input without stopping and waiting. Timing is an issue so I
> need the loop to continue uninterrupted if there isn't any command
> to
> stop it.
>
> Brie Howley wrote:
>>
>>
>> Is there a way to run a while loop that will go on indefinitely
>> until
>> a user input (keyboard command) tells it to stop? I can start
> the
>> while loop with a user command but I can't figure out how to
stop
>> it
>> and go on to the next part of the program.
>>
>> command = input('[Enter] to run, [Q] to quit: ');
>> r=1;
>> while isempty(command)==1
>> r=r+1;
>> end

If you're lucky, my <getkeynow> function will work for you:

% Example usage
getkeynow('init') ;
ch = 0 ;
t = 0 ;
disp('Press <escape> to quit') ;
while ~isequal(ch,char(27)),
ch = getkeynow ;
t = t + 1 ;
end
getkeynow('exit') ;
fprintf('\n%d loops completed',t) ;

Works in my ML version 6.5

<getkeynow>, as well as <getkey> and <getkeywait>
which might be usefull as well, are available through here on the
FEX:
<http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1094450&objectType=author>

hth
Jos
From: Brie on
The <getkeynow> function is exactly what I need.
Unfortunately, I don't have Java on my system. Is there a work
around?

jos wrote:
>
>
> Brie wrote:
>>
>>
>> I guess what I need to know is if there is a command that
checks
>> for
>> user input without stopping and waiting. Timing is an issue so
I
>> need the loop to continue uninterrupted if there isn't any
> command
>> to
>> stop it.
>>
>> Brie Howley wrote:
>>>
>>>
>>> Is there a way to run a while loop that will go on
> indefinitely
>>> until
>>> a user input (keyboard command) tells it to stop? I can
> start
>> the
>>> while loop with a user command but I can't figure out how
to
> stop
>>> it
>>> and go on to the next part of the program.
>>>
>>> command = input('[Enter] to run, [Q] to quit: ');
>>> r=1;
>>> while isempty(command)==1
>>> r=r+1;
>>> end
>
> If you're lucky, my <getkeynow> function will work for you:
>
> % Example usage
> getkeynow('init') ;
> ch = 0 ;
> t = 0 ;
> disp('Press <escape> to quit') ;
> while ~isequal(ch,char(27)),
> ch = getkeynow ;
> t = t + 1 ;
> end
> getkeynow('exit') ;
> fprintf('\n%d loops completed',t) ;
>
> Works in my ML version 6.5
>
> <getkeynow>, as well as <getkey> and <getkeywait>
> which might be usefull as well, are available through here on the
> FEX:
> <http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1094450&objectType=author>
>
> hth
> Jos
 |  Next  |  Last
Pages: 1 2
Prev: MSK BER simulation
Next: a question about matrix