I would like to use MATLAB from the windows command line. I need some
scripts to run in the background but I couldn't really find a way how
to do this. I also look in the site for some clues on how to do it
but till now I couldn't find anything about it. I am sure it is out
there - some list of commands or some tips about it.
Do you know a link or how this is being done??
Thank
Noam
Did you try typing:
matlab -h
from a DOS window?
In brief, you can run your .m file, say mymfile.m like this:
matlab -r mymfile
providing it is in the Matlab path.
Many thanks for the tip.
I just gave it a try but it simply opens the MATLAB GUI as usual.
I also tried matlab -nodesktop from the command line (cmd or DOS).
What I get is a MATLAB console without a graphical GUI but this is
not exactly what I am looking for.
My aim is to control MATLAB with the help of the programming language
PHP. If I could give MATLAB commands over the DOS primpt line I could
do what ever I wanted with it and automate MATLAB.
I have MATLAB 7.0
Thanks
Noam
I assume you're using Win XP???
You need to go to Programs\Accessories\Command Prompt
A black window should open.
Type:
matlab -h
Believe me, it works.
I have 25 routines operating on an hourly schedule using the matlab -r
facility.
The only thing you need to be aware of is that you need an exit at the
bottom of each .m file, otherwise a Matlab will open each time and
stay open. I found the Matlab r2006b did not do this properly and one
morning I ended up with about 400 Matlabs open. I fixed this by
reverting to Version 2006a.
Sorry for the last post - for some reason I got it empty...
That was exactly what I did yesterday :-(
I do use WinXP as you guessed. When I open the command line and type
matlab -h, MATLAB simply starts with the normal GUI as if I started
it by double-clicking on the matlab.exe file.
Pay attention that I didn't try to run any MATLAB script with the
command you gave me. I was hoping I will get a help list from the
command line that will give me instructions how to control a script
from the command line.
I am intending on delivering an array to a MATLAB script, processing
this array and returning some values.
I would like to do this with the help of PHP that is able to call
applications via command line and for that reason I can't use any GUI
functionality. Is that doable?
Anyhow - I don't manage to run MATLAB from the command line by using
the command you gave me.
Any further hints you could throw at my direction? I really
appreciate your efforts!
Thanks
Noam
NZTideMan wrote:
>
>
> On Jul 5, 9:58 am, Noam <behemothk...@hotmail.com> wrote:
>> Hi NZTideMan,
>>
>> Many thanks for the tip.
>> I just gave it a try but it simply opens the MATLAB GUI as
usual.
>> I also tried matlab -nodesktop from the command line (cmd or
> DOS).
>> What I get is a MATLAB console without a graphical GUI but this
> is
>> not exactly what I am looking for.
>>
>> My aim is to control MATLAB with the help of the programming
> language
>> PHP. If I could give MATLAB commands over the DOS primpt line I
> could
>> do what ever I wanted with it and automate MATLAB.
>>
>> I have MATLAB 7.0
>>
>> Thanks
>> Noam
>>
>>
>>
>>
>>
>> NZTideMan wrote:
>>
>> > On Jul 5, 8:06 am, Noam <behemothk...@hotmail.com>
wrote:
I don't understand.........
Did you use Start\Run?
or did you do what I suggested and go Start\Programs\Accessories
\Command Prompt?
When you do this, does a black window open? It should be called
Command Prompt, and there should be line with a blinking cursor.
Something like this:
c:\>_
What happens when you type matlab -h into that black window?
Not that it matters, actually, because when you use matalb -r mfile it
opens a Matlab window and executes the .m file, but as I mentioned the
window will stay open unless you put an exit at the bottom of your .m
file.
I am not sure how far the command-line capabilities of matlab extend, but matlab CAN be definitely run in the batch mode. To get that to work, you should work in the xx\Matlab_installation_directory\bin\ directory. Then if you use the matlab -h command, it pulls up the batch file help info. (You need to be located in the directory with the batch file[matlab.bat] in there).
The reason why you get the matlab Java window (the desktop, with all the bells and horns) pop up when you type matlab -h now, is that 'matlab' is being recognized by the cmd interface to be the matlab executable, matlab.exe. I expect the other person, NZ.. already set his environment variables up to have 'matlab' refer to the .bat file instead of .exe.
So anyway, if you want to execute a wastedeffort.m file that you wrote up for batch processing, then you say: xx\matlab_installation_directory\bin> matlab -r wastedeffort.m. If you don't want any pesky matlab java window, then you say: xx\matlab_installation_directory\bin> matlab -automation -r wastedeffort.m.
I expect that you want to FORCE the windows CLI to behave like the matlab CLI, where you can declare variables/functions and have arithmetic I/O etc. I havent found a way of doing that so far without writing separate batch files so far. Another way is to (like Timo Salmi's tsfunc17) use C/C++ or use mex-stuff (I have no clue about mex) to create an original executable that carries out the i/o.
But that solution might be worse than the problem, if you don't like that kind of a thing.
Word of caution, Timo wrote tsfunc17 in 98.
-Take care
Sid
I am not sure how far the command-line capabilities of matlab extend, but matlab CAN be definitely run in the batch mode. To get that to work, you should work in the xx\Matlab_installation_directory\bin\ directory. Then if you use the matlab -h command, it pulls up the batch file help info. (You need to be located in the directory with the batch file[matlab.bat] in there).
Thanks either way.
"Sid H" <ssh...@xx.com> wrote in message <gpf4pd$e1d$1...@fred.mathworks.com>...
Here is an unsupported and undocumented code snippet to programmatically disappear the desktop, editor and all the other windows that might pop-up when you open Matlab (depending on your default docking state):
frames = java.awt.Frame.getFrames;
for frameIdx = 1 : length(frames)
try
awtinvoke(frames(frameIdx),'setVisible',0);
catch
% never mind...
end
end
If you only wish to hide the desktop, then you don't need a loop - running awtinvoke on frames(1) will be enough. To unhide the windows, simply rerun the above with awtinvoke(...,...,1). Remember to place 'exit' in your m-code or you won't be able to close Matlab after the script finishes except using the task manager.
Yair Altman
http://Undocumented-Matlab.com
I have another question in mind--is there a way to do similar task (hiding the screen) for any window that has opened apart from matlab window? I have been seeking help on this for the last few days, but I can see only those using "autohotkeys" where-in you need to manually do it in person using the keyboard to hide or unhide an opened window. Could you please throw a code that can do similar job for an opened window (other than matlab). If we can name the opened window that has to be hidden/unhidden that would be just awesome. Thanks once again for your help.
Vinod
"Yair Altman" <altma...@gmailDEL.comDEL> wrote in message <gq7a3n$qus$1...@fred.mathworks.com>...
Come on!
set(hFig,'Visible','off')
Only hiding desktop-related windows is undocumented - hiding normal windows is fully supported
Yair Altman
http://undocumented-matlab.com
"Yair Altman" <altma...@gmailDEL.comDEL> wrote in message <gqa694$e7m$1...@fred.mathworks.com>...
as an extention of this topic I have a question. I can run matlab from batch file and it works. But I need myfile.m to return me a value (return 0 if everything is ok; return ErrorCode if somethings is not OK). If I try the following code:
matlab -nosplash -nodesktop -minimize -r "myfile(arg1, arg2,...)" -wait
echo %ERRORLEVEL%
then I always obtain ERRORLEVEL = 0 in any case (both if OK and not OK). Can I somehow control than myfile works properly by using ErrorCode in external application? I need to send ErrorCode from matlab to ... any external application. How I can do it? In definition of myfile.m there is a string:
function [Status] = myfile(arg1, arg2, ...)
but it doesn't work as I need to.
Thank in advance