PDA

查看完整版本 : MATLAB脚本是否可能根据其执行的操作系统而有所不同?


poster
2019-12-10, 16:49
我在Linux和Windows XP上都运行MATLAB。我的文件在我使用的所有计算机之间同步,但是由于Linux和Windows之间目录结构的差异,我必须为不同的操作系统分别设置导入和导出行。目前,我只是为错误的OS注释掉行,但是我想知道是否可以编写类似以下内容的代码:

if OS == Windows datafile = csvread('C:\Documents and Settings\Me\MyPath\inputfile.csv'); else datafile = csvread('/home/Me/MyPath/inputfile.csv'); end 这也是一个更普遍的问题,适用于希望使用MATLAB system('command')从MATLAB内部执行系统命令的情况。


回答:
您可以使用ispc (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ispc.shtml) / isunix (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/isunix.html) / ismac (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ismac.html)函数来确定平台,甚至可以使用计算机 (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/computer.shtml)功能来获取有关计算机 (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/computer.shtml)的更多信息。

if ispc datafile = csvread('C:\Documents and Settings\Me\MyPath\inputfile.csv'); else datafile = csvread('/home/Me/MyPath/inputfile.csv'); end

更多&回答... (https://stackoverflow.com/questions/1575269)