![]() |
MATLAB脚本是否可能根据其执行的操作系统而有所不同?
我在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内部执行系统命令的情况。 回答: 您可以使用[B][URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ispc.shtml"]ispc[/URL][/B] / [B][URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/isunix.html"]isunix[/URL][/B] / [B][URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ismac.html"]ismac[/URL][/B]函数来确定平台,甚至可以使用[B][URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/computer.shtml"]计算机[/URL][/B]功能来获取有关[B][URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/computer.shtml"]计算机[/URL][/B]的更多信息。 if ispc datafile = csvread('C:\Documents and Settings\Me\MyPath\inputfile.csv'); else datafile = csvread('/home/Me/MyPath/inputfile.csv'); end [url=https://stackoverflow.com/questions/1575269]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 23:27。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.