通过php调用linux命令,可以实现远程调用matlab.
试验环境:Fedora16,matlab2012blinuxversion,Googlechrome18.0.1025.108beta
以下代码实现了在网页输入matlab命令并显示执行结果。注意:如果不加-nodisplay选项,会出现"nodisplayspecified"的警告,当然可以在执行matlab命令之前unsetDISPLAY也可以直接在terminal执行matlab。
以下代码对于plot()等绘图命令会出现{Warning:Objectsofgraph2d.lineseriesclassexist-notclearingthisclassoranyofitssuper-classes}错误,目前未解决(也就是无法绘图)。但是通过ssh远程登陆服务器调用相同命令可以plot并save图像,不解。
输入sin(1:10)进行简单计算
输入ver命令获取版本信息
直接终端运行
参考资料:
mathwork关于matlab启动参数的介绍:
SpecifyingMATLABStartupOptions
Youcanspecifystartupoptions(alsocalledcommandflagsorcommandlineswitches)thatinstructtheMATLABprogramtoperformcertainoperationswhenyoustartit.Onallplatforms,youspecifytheoptionsasargumentstothematlabcommandwhenyoustartisattheoperatingsystemprompt.Forexample,thefollowingstartsMATLABandsuppressesthedisplayofthesplashscreen.
matlab-nosplash
OnWindowsplatforms,youcanprecedeastartupoptionwitheitherahyphen(-)oraslash(/).Forexample,-nosplashand/nosplashareequivalent.
Onallplatforms,youcanalsospecifystartupoptionsusingaMATLABstartupfile—seeSpecifyingStartupOptionsintheMATLABStartupFile
OnWindowsplatforms,youcanspecifystartupoptionsintheMATLABshortcut—seeIncludingStartupOptionsinaShortcutonWindowsSystems.
Youcanaddselectedstartupoptions(alsocalledcommandflagsorswitchesforthecommandline)tothetargetpathforyourshortcutintheWindowsenvironmentforMATLAB.Formoreinformationabouttheoptions,seeCommonlyUsedStartupOptions.
TousestartupoptionsfortheMATLABshortcuticoninaWindowsenvironment,followthesesteps:
ThisexampleinstructsMATLABtoautomaticallyrunthefileresultsafterstartup,whereresults.misinthestartupfolderoronthesearchpathforMATLAB.ThestatementintheTargetfieldmightappearas
Atstartup,MATLABautomaticallyexecutesthefilematlabrc.mand,ifitexists,startup.m.Thefilematlabrc.m,whichisinthematlabroot/toolbox/localfolder,isreservedforusebyMathWorksandbythesystemmanageronmultiusersystems.
Thefilestartup.misforyoutospecifystartupoptions.Forexample,youcanmodifythedefaultsearchpath,predefinevariablesinyourworkspace,ordefinedefaultsforHandleGraphicsobjects.Usethefollowingstatementsinastartup.mfiletoaddthespecifiedfolder,/home/username/mytools,tothesearchpath,andtochangethecurrentfoldertomytoolsuponstartup.
Platform
Option
Description
All
-clicensefile
SetLM_LICENSE_FILEtolicensefile.Itcanhavetheform[emailprotected].
-hor-help
Displaystartupoptions(withoutstartingMATLAB).
-logfile"logfilename"
AutomaticallywriteoutputfromMATLABtothespecifiedlogfile.
Windowsplatforms
-minimize
StartMATLABwiththedesktopminimized.AnydesktoptoolsordocumentsthatwereundockedwhenMATLABwaslastclosedwillnotbeminimizeduponstartup.
UNIXplatforms
-nojvm
StartMATLABwithoutloadingtheSunMicrosystemsJVMsoftware.Thisminimizesmemoryusageandimprovesinitialstartupspeed,butrestrictsfunctionality.Withnojvm,youcannotusethedesktop,figures,oranytoolsthatrequireJavasoftware.
Forexample,youcannotsetpreferencesifyoustartMATLABwiththe-nojvmoption.However,youcanstartMATLABoncewithoutthe-nojvmoption,setthepreference,andquitMATLAB.MATLABremembersthatpreferencewhenyoustartitagain,evenifyouusethe-nojvmoption.
-nosplash
StartMATLABwithoutdisplayingitssplashscreen.
-r"statement"
AutomaticallyrunthespecifiedstatementimmediatelyafterMATLABstarts.ThisissometimesreferredtoascallingMATLABinbatchmode.FilesyourunmustbeinthestartupfolderforMATLABoronthesearchpath.Donotincludepathnamesorfileextensions.Enclosethestatementindoublequotationmarks("statement").Usesemicolonsorcommastoseparatemultiplestatements
-singleCompThread
LimitMATLABtoasinglecomputationalthread.Bydefault,Windowsmakesuseofthemultithreadingcapabilitiesofthecomputeronwhichitisrunning.
YoucanpassPerlvariablestoMATLABonstartupbyusingthe-roptionofthematlabfunction.Forexample,assumeaMATLABfunctiontestthattakesoneinputvariable:
TopassaPerlvariableinsteadofaconstantastheinputparameter,followthesesteps.
Formoreinformation,seethematlab(Windows)ormatlab(UNIX)referencepage.
WhentheMATLABprogramstarts,itconstructstheclasspathforSunMicrosystemsJavasoftwareusinglibrarypath.txtaswellasclasspath.txt.IfyoucallJavasoftwarefromMATLAB,seemoreaboutthisinTheJavaClassPathandLocatingNativeMethodLibrariesintheMATLABExternalInterfacesdocumentation.
===============================================================================================================================
StartMATLABusingthecommand:
First,gotothedirectorycontainingtheMATLABscriptthatdefinesthefunction(or,fancier,addthatdirectoryintoMATLABPATHbyeditingyourMATLABPATHenvironmentvariableorpathdef.mfile).Then,runlikethis