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:
Looking for way to keep Matlab idle using m-code (for Windows application)

Subject: Looking for way to keep Matlab idle using m-code (for Windows application)

From: Sunil

Date: 25 Aug, 2010 15:28:05

Message: 1 of 9

Dear All,

Is it possible to keep Matlab idle (for some time, let's say 60 secs) using m-code and then run the same / another m-code program iteratively.
I want this, beacuse I am facing some problem with Matlab memory and it doesn't after n no of iterations in my program. But it runs for several iterations (without quitting Matlab) if I run every single iteration and keep Matlab idle for some time.

Hope you understood my problem.

Best Regards,
Sunil

Subject: Looking for way to keep Matlab idle using m-code (for Windows application)

From: Andy

Date: 25 Aug, 2010 15:36:04

Message: 2 of 9

"Sunil " <sunil.nagtilak@gmail.com> wrote in message <i53cq5$31g$1@fred.mathworks.com>...
> Dear All,
>
> Is it possible to keep Matlab idle (for some time, let's say 60 secs) using m-code and then run the same / another m-code program iteratively.
> I want this, beacuse I am facing some problem with Matlab memory and it doesn't after n no of iterations in my program. But it runs for several iterations (without quitting Matlab) if I run every single iteration and keep Matlab idle for some time.
>
> Hope you understood my problem.
>
> Best Regards,
> Sunil

doc pause

Subject: Looking for way to keep Matlab idle using m-code (for Windows application)

From: Sunil

Date: 25 Aug, 2010 16:02:20

Message: 3 of 9


> doc pause
Hello Andy,
Sorry i forgot to mention that i have already tried pause cmd, but it will not idle Matlab and it is not working for me. What I am looking for is something which can idle Matlab, in simple words it should show ">>" in command window

Sunil

Subject: Looking for way to keep Matlab idle using m-code (for Windows application)

From: Sean

Date: 25 Aug, 2010 17:00:23

Message: 4 of 9

"Sunil " <sunil.nagtilak@gmail.com> wrote in message <i53eqc$i52$1@fred.mathworks.com>...
>
> > doc pause
> Hello Andy,
> Sorry i forgot to mention that i have already tried pause cmd, but it will not idle Matlab and it is not working for me. What I am looking for is something which can idle Matlab, in simple words it should show ">>" in command window
>
> Sunil

doc timer

Subject: Looking for way to keep Matlab idle using m-code (for Windows application)

From: Sunil

Date: 25 Aug, 2010 20:44:05

Message: 5 of 9

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i53i77$rta$1@fred.mathworks.com>...

> doc timer

Hello Sean

I think 'timer' should work for my problem.. I tried to use this cmd in my code is one of my while loop with timer period of 180 secs.. but instead of waiting 180 secs to execute the TimerFcn it goes to next line in m-code. I want program to wait till it exceutes the TimerFcn and then goto next line in the code. I tried using a while loop with condition on task executed, but when i run this code my Matlab could not terminate it!!? even Ctrl+c is also not terminating this program :P
here is my code
================================
clear all;
clc;
tasks=0;
while (tasks<=0)
    t = timer('StartDelay', 10,'Period', 1,'TasksToExecute', 1,...
        'ExecutionMode','fixedRate');

    t.StartFcn = {'my_callback_fcn', 'My start message'};
    t.TimerFcn = 'my_cal';
    t.StopFcn = { @my_callback_fcn, 'My stop message'};
    start(t)
    no=get(t, {'TasksExecuted'});
    tasks=no{1};
end
=============================

other functions
function my_cal(obj, event)
x=12*12
pause(10)

function my_callback_fcn(obj, event, string_arg)
txt1 = 'WAIT';
event_type = event.Type;
event_time = datestr(event.Data.time);
msg = txt1;
disp(msg)

Subject: Looking for way to keep Matlab idle using m-code (for Windows application)

From: Sean

Date: 25 Aug, 2010 21:01:24

Message: 6 of 9

"Sunil " <sunil.nagtilak@gmail.com> wrote in message <i53val$63u$1@fred.mathworks.com>...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i53i77$rta$1@fred.mathworks.com>...
>
> > doc timer
>
> Hello Sean
>
> I think 'timer' should work for my problem.. I tried to use this cmd in my code is one of my while loop with timer period of 180 secs.. but instead of waiting 180 secs to execute the TimerFcn it goes to next line in m-code. I want program to wait till it exceutes the TimerFcn and then goto next line in the code. I tried using a while loop with condition on task executed, but when i run this code my Matlab could not terminate it!!? even Ctrl+c is also not terminating this program :P
> here is my code
> ================================
> clear all;
> clc;
> tasks=0;
> while (tasks<=0)
> t = timer('StartDelay', 10,'Period', 1,'TasksToExecute', 1,...
> 'ExecutionMode','fixedRate');
>
> t.StartFcn = {'my_callback_fcn', 'My start message'};
> t.TimerFcn = 'my_cal';
> t.StopFcn = { @my_callback_fcn, 'My stop message'};
> start(t)
> no=get(t, {'TasksExecuted'});
> tasks=no{1};
> end
> =============================
>
> other functions
> function my_cal(obj, event)
> x=12*12
> pause(10)
>
> function my_callback_fcn(obj, event, string_arg)
> txt1 = 'WAIT';
> event_type = event.Type;
> event_time = datestr(event.Data.time);
> msg = txt1;
> disp(msg)

You're close! Run this:
%
T = timer('timerfcn','disp(''Hello World'')','ExecutionMode','fixedRate','Period',7)
start(T)
%
Now every seven seconds it'll display 'Hello World' to the command line. You can do whatever else you want while this is running.

What you were doing above is creating a new timer every time through the loop which defeats the purpose of timers. What you want is one timer that sits in the background and does its thing whenever it has to; leaving everything else open.

Subject: Looking for way to keep Matlab idle using m-code (for Windows application)

From: Sunil

Date: 26 Aug, 2010 12:28:07

Message: 7 of 9

> You're close! Run this:
> %
> T = timer('timerfcn','disp(''Hello World'')','ExecutionMode','fixedRate','Period',7)
> start(T)
> %
> Now every seven seconds it'll display 'Hello World' to the command line. You can do whatever else you want while this is running.
>
> What you were doing above is creating a new timer every time through the loop which defeats the purpose of timers. What you want is one timer that sits in the background and does its thing whenever it has to; leaving everything else open.

Hello Sean,

My main concern is that I don't want to run any other application while my timer function is running !! Is that possible?

Sunil

Subject: Looking for way to keep Matlab idle using m-code (for Windows application)

From: Steven_Lord

Date: 26 Aug, 2010 13:20:51

Message: 8 of 9



"Sunil " <sunil.nagtilak@gmail.com> wrote in message
news:i55mkn$mm8$1@fred.mathworks.com...
>> You're close! Run this:
>> %
>> T = timer('timerfcn','disp(''Hello
>> World'')','ExecutionMode','fixedRate','Period',7)
>> start(T)
>> %
>> Now every seven seconds it'll display 'Hello World' to the command line.
>> You can do whatever else you want while this is running.
>>
>> What you were doing above is creating a new timer every time through the
>> loop which defeats the purpose of timers. What you want is one timer
>> that sits in the background and does its thing whenever it has to;
>> leaving everything else open.
>
> Hello Sean,
>
> My main concern is that I don't want to run any other application while my
> timer function is running !! Is that possible?

Then what you want is PAUSE.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Looking for way to keep Matlab idle using m-code (for Windows application)

From: Sunil

Date: 26 Aug, 2010 18:17:21

Message: 9 of 9


>
> Then what you want is PAUSE.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Hello Steve,

I already tried using pause and after some runs in loop I am getting following error

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

Please let me know if anybody is aware this problem with Matlab memory and any solution to this.

Sunil

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