[Blindmath] running matlab in batch mode

Godfrey, Jonathan via Blindmath blindmath at nfbnet.org
Mon May 19 22:21:22 UTC 2014


Hi all,

Recall that I said last week that we were trying to get matlab running in batch mode. I asked the student to do a couple of extra tests for my interest while I was solving her problems.
Our little experiment seemed to work sufficiently well for her and I now share it with the list. The text that would be put in a batch file would be something like:
<starts>
c:\progra~1\matlab\R2010b\bin\matlab.exe -r BATCHTest20140516.m -logfile Log2.txt
<ends>
Obviously the path needs to match the installation on your own machine.

As it happens, you don't need the last log file command as this only produces the output without the commands. You can get the output by adding the standard matlab command for a diary to be kept at the start of our script file. The script file must have an exit command as well otherwise the matlab session remains open. Note that the diary does include any errors resulting from poor input. (yes we had one of those during testing.)

The test script file was as follows:
<starts>
diary on
U = rand(7)
dlmwrite('Rand7.csv', U)
diary off
quit
<ends>
And the resulting diary file is
<starts>
U =

    0.8147    0.5469    0.8003    0.0357    0.6555    0.8235    0.7655
    0.9058    0.9575    0.1419    0.8491    0.1712    0.6948    0.7952
    0.1270    0.9649    0.4218    0.9340    0.7060    0.3171    0.1869
    0.9134    0.1576    0.9157    0.6787    0.0318    0.9502    0.4898
    0.6324    0.9706    0.7922    0.7577    0.2769    0.0344    0.4456
    0.0975    0.9572    0.9595    0.7431    0.0462    0.4387    0.6463
    0.2785    0.4854    0.6557    0.3922    0.0971    0.3816    0.7094
<ends>
This is better than the log file that is generated by the batch file process as it doesn't include the matlab splash screen.

So, we didn't get the commands interwoven with the output which might prove useful, but use of the diary does lend itself to how one could work interactively in matlab. Note that this work around has been used in many other software applications for years, especially such statistical software as SPSS and Stata.

If the diary command is entered in matlab using a file name such as Today.txt, then the user could open the resulting text file in a browser. Once any commands that would normally lead to output were issued in matlab, you would switch to the browser, hit f5 to refresh the session and check out what appears at the bottom.

I accept that this isn't exactly convenient, and it isn't what I consider accessibility, but the time for arguing with tech support staff who don't understand the problem is after the final exam, not during the semester.

I also note that no one has mentioned using alternatives such as Octave (the script file here should work in Octave) or an entirely different tool such as Maxima. As it happens, I don't use matlab at all as I have Octave and Maxima at hand for those rare occasions when my normal tools can't provide a solution.

Hope this helps.
Jonathan





More information about the BlindMath mailing list