How can I run a matlab function in batch on Windows?

Hi,
I am working with R2011a on a Windows 7 desktop computer.
I have an m file that requires two input parameters (input file, output file). It works just fine. I need to run this file and call the same function using different input files.
What I thought would work was to write a simple Perl script, store input arguments, system the Matlab function passing arguments one by one. Ideally, Matlab would wait for the function to be done with an input file, and then start processing the next input file.
However, it did not work. My command line on cygwin looks like this:
foreach my $input (@inputs){
my $command = ` matlab.exe -nodesktop -nojvm -nodisplay -nosplash -minimize -wait -r "cd('C:/Users/working_directory'); process_input_file('input.txt', 'output.txt'); disp('success'); exit"
}
Any pointer would be greatly appreciated.
Thank you.

Réponses (1)

Jan
Jan le 12 Fév 2015

0 votes

The PERL code does not depend on the contents of the input "inputs". You are calling Matlab with exactly the same input files. Is this the behavior that you explain by "it did not work"? Or do you observe any other problem?
If the question concerns PERL, please visit a PERL forum, because the Matlab part is fine.
Why don't you create the loop inside Matlab directly?

1 commentaire

gconroy
gconroy le 13 Fév 2015
Thanks for your response.
Sorry that I did not detail what did not work. The for loop gives Matlab first input, Matlab runs without any problem, outputs correctly; however, PERL terminates (and returns to the shell) before Matlab has a chance to run with the next set of inputs.
I reckon that this premature termination may have something to do with Matlab rather than PERL.
When I remove the exit command from Matlab run, PERL waits for me to close the Matlab window in order to proceed with the next iteration in the for loop. Thus, I would like to automate the "close the Matlab window once success is displayed" part, however, adding exit does not seem to do the job.
PS. Sure, this is meant to be a pseudo-code. Input arguments are defined, modified (path correction, adequate file naming etc.) and then passed within the loop.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange

Question posée :

le 12 Fév 2015

Commenté :

le 13 Fév 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by