Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
infinite loop

Subject: infinite loop

From: Bilal

Date: 16 Jul, 2010 13:43:05

Message: 1 of 4

Hi,
I wanted to know how to have an infinite loop in Matlab. usually people want to avoid this but I actually want it.
I want my program to run continuously until i hit a key, for example "x". How can I manage to have the program exit upon pressing "x"?
Bilal

Subject: infinite loop

From: Sean

Date: 16 Jul, 2010 13:48:17

Message: 2 of 4

"Bilal " <bilalhaider87@gmail.com> wrote in message <i1pnl8$jhf$1@fred.mathworks.com>...
> Hi,
> I wanted to know how to have an infinite loop in Matlab. usually people want to avoid this but I actually want it.
> I want my program to run continuously until i hit a key, for example "x". How can I manage to have the program exit upon pressing "x"?
> Bilal

while 1
   %do stuff
end

Don't use x. Use ctrl+c on a PC or cmd+. on a MAC.

Subject: infinite loop

From: someone

Date: 16 Jul, 2010 13:54:04

Message: 3 of 4

"Bilal " <bilalhaider87@gmail.com> wrote in message <i1pnl8$jhf$1@fred.mathworks.com>...
> Hi,
> I wanted to know how to have an infinite loop in Matlab. usually people want to avoid this but I actually want it.
> I want my program to run continuously until i hit a key, for example "x". How can I manage to have the program exit upon pressing "x"?
> Bilal

% Perhaps something like this:

x = 1;
while x
  % insert code here
   if "key is pressed"
      x = 0;
   end
end

Subject: infinite loop

From: Thomas

Date: 13 Sep, 2013 07:11:07

Message: 4 of 4

"Bilal " <bilalhaider87@gmail.com> wrote in message <i1pnl8$jhf$1@fred.mathworks.com>...
> Hi,
> I wanted to know how to have an infinite loop in Matlab. usually people want to avoid this but I actually want it.
> I want my program to run continuously until i hit a key, for example "x". How can I manage to have the program exit upon pressing "x"?
> Bilal

Try
'pause'

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us