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

New to MATLAB?

Thread Subject:
Calling function during the same script run repeatedly

Subject: Calling function during the same script run repeatedly

From: Martyna

Date: 25 Oct, 2012 08:09:07

Message: 1 of 2

Dear Community,
I have a script file, say example.m, that calls a function, say fun, repeatedly. Each time this function is called during the same script run, a text file with outputs is generated. When the script will be run the next time, all text files generated during the previous script run will be removed. I would like to distinguish whether fun is invoked in the same script run (so that no output text files with are removed) or fun is invoked in any other script run (in this case output text files are deleted). Have you any ideas how to solve this? Many thanks in advance for your hints.


Subject: Calling function during the same script run repeatedly

From: Sadik

Date: 26 Oct, 2012 00:17:09

Message: 2 of 2

You can generate a random number within your script each time you run it. A better one that avoids having the same ID more than once is keeping a variable in your base workspace and never clearing it and incrementing it each time you run your script. This will serve as a process ID. You will also define an additional input to your function to get this ID from the script. Now you know from which script your function is being called. You also had better put this ID into the name of the text files as a prefix so that you will never delete a text file.

Tags for this Thread

No tags are associated with 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