How to execute my code over and over??

  • Follow


Hi there,

First of all, thanks so much to everyone who has been helping me with my code so far; you have been so helpful!

Okay, now that i have my code working nicely i want to run it several times in a row with various input parameters.  My function analyzes data and outputs a struct based on the input parameters and I want to have it provide output for several different inputs.

In the command console it would look like this:

>> interval_1min = myFunction(1)
>> interval_2min = myFunction(2)
>> interval_3min = myFunction(3)
..
..
..

and I want to do this for a bunch of different inputs but each time it takes about 2hrs so I want it to do a bunch of them overnight.  I hope this is clear.  I'm pretty sure it is simple to do this with an m-file or something but I am a MATLAB beginner so I dont know the best way to go about it.

Thanks in advance!!
0
Reply Adam 7/27/2010 12:07:03 AM

On Jul 27, 12:07=A0pm, "Adam Thibideau" <adam.thibid...@gmail.com>
wrote:
> Hi there,
>
> First of all, thanks so much to everyone who has been helping me with my =
code so far; you have been so helpful!
>
> Okay, now that i have my code working nicely i want to run it several tim=
es in a row with various input parameters. =A0My function analyzes data and=
 outputs a struct based on the input parameters and I want to have it provi=
de output for several different inputs.
>
> In the command console it would look like this:
>
> >> interval_1min =3D myFunction(1)
> >> interval_2min =3D myFunction(2)
> >> interval_3min =3D myFunction(3)
>
> .
> .
> .
>
> and I want to do this for a bunch of different inputs but each time it ta=
kes about 2hrs so I want it to do a bunch of them overnight. =A0I hope this=
 is clear. =A0I'm pretty sure it is simple to do this with an m-file or som=
ething but I am a MATLAB beginner so I dont know the best way to go about i=
t.
>
> Thanks in advance!!

Don't do this!!

Read this:
http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1.2C=
_A2.2C....2CA10_in_a_loop.3F
0
Reply TideMan 7/27/2010 12:46:19 AM


> Don't do this!!
> 
> Read this:
> http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F


Thats not what i want though.  I want the output from each iteration of my function to be assigned to a variable.  I want to have the code get executed overnight just as if I was sitting beside the computer and typing in the next command when the previous one finished.  Understand?
0
Reply Adam 7/27/2010 1:09:04 AM

"Adam Thibideau" <adam.thibideau@gmail.com> wrote in message <i2lbjf$ie1$1@fred.mathworks.com>...
> 
> > Don't do this!!
> > 
> > Read this:
> > http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
> 
> 
> Thats not what i want though.  I want the output from each iteration of my function to be assigned to a variable.  I want to have the code get executed overnight just as if I was sitting beside the computer and typing in the next command when the previous one finished.  Understand?

How about a while or for loop that just loops the number of functions or whatever you want to do?  Each loop, you could be reading an input with your function parameters.  Make sure that for ever output, you save it (use save for variables or saveas for figures) and close it, or else MATLAB will get bogged down quickly.
0
Reply Judy 7/27/2010 1:37:03 AM

On Jul 27, 1:09=A0pm, "Adam Thibideau" <adam.thibid...@gmail.com> wrote:
> > Don't do this!!
>
> > Read this:
> >http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables...
>
> Thats not what i want though. =A0I want the output from each iteration of=
 my function to be assigned to a variable. =A0I want to have the code get e=
xecuted overnight just as if I was sitting beside the computer and typing i=
n the next command when the previous one finished. =A0Understand?

I understand, but what I'm saying is that you should NOT assign the
output to variables defined like that.  And I gave you that reference
in the FAQ because it not only shows how to assign variables
correctly, but also shows a for loop, which is what you're looking
for.
Did you not grasp that when you read the FAQ?
0
Reply TideMan 7/27/2010 2:15:42 AM

No sorry I did not.  Maybe if you would have offered a little more explaination to your solution than "dont do this" i would have grasped it.
0
Reply Adam 7/27/2010 2:34:05 AM

To be even more explicit, do something like this:

% pre-allocation goes here.
for ii = 1:5
    interval(ii).min = min(rand(ii));  % For example
end
% Now look at:   interval(4).min


OR this:


% pre-allocation goes here.
for ii = 1:5
    interval_min{ii} = min(rand(ii));  % For example
end
% Now look at:   interval_min{4}
0
Reply Matt 7/27/2010 2:39:04 AM

Adam Thibideau wrote:
> No sorry I did not.  Maybe if you would have offered a little more 
> explaination to your solution than "dont do this" i would have grasped it.

In your opinion, how long of a tutorial should we write in response to 
each of the several hundred questions posted each day?
0
Reply Walter 7/27/2010 3:30:10 AM

Just a passing thought: If your code works in serial fashion, why don't you consider PARFORing it?

http://www.mathworks.com/access/helpdesk/help/toolbox/distcomp/brb2x2l-1.html

Thanks,

Saurabh
0
Reply Saurabh 7/28/2010 10:18:21 PM

"Adam Thibideau" <adam.thibideau@gmail.com> wrote in message <i2lgis$7d9$1@fred.mathworks.com>...
> No sorry I did not.  Maybe if you would have offered a little more explaination to your solution than "dont do this" i would have grasped it.

You should try to digest the FAQ, the answer you received was the correct one. It is hard to manipulate variables if you create them in the way you describe. You will end up having to use the eval function, which is really not ideal. If you index as suggested then your code will be more elegant, compact and easy to understand. It will also make it easier to extract the data which you want. 
0
Reply Rob 7/28/2010 11:30:25 PM

9 Replies
250 Views

(page loaded in 0.235 seconds)

Similiar Articles:













7/23/2012 2:59:17 PM


Reply: