个人工具

MATLAB

来自Ubuntu中文

Chongpapa讨论 | 贡献2009年1月17日 (六) 17:28的版本 安装MATLAB

跳转至: 导航, 搜索

MATLAB

原文出处:

原文作者:

授权许可:

翻译人员:WeiTao ChengZhang gosman

校正人员:

贡献人员:

适用版本: 文章状态:等待翻译



Prerequisites

At a minimum, you don't need much to run MATLAB. It will run in the console without X just fine, though naturally missing some functionality such as graphing. Most users, however, use many of the bells and whistles. The Prerequisites section is made with that in mind.

为了使用 MATLAB 桌面,向导,Simulink ,和很完美的图像,你需要安装 Java ,并且在你的路径内可以执行。如果你没有,你必须从终端中运行,这个并不好。最快检测你是否拥有 java 路径的方法是在终端中运行 which java.。如果它返回了例如 /usr/local/bin ,那是正常的,否则你需要按照 Java How-To 的说明来配置。

You will get far better performance making complex graphs if you are using hardware rendered openGL. In other words, a videocard. Open up a terminal and run the following command. 模板:Grep Driver /etc/X11/xorg.conf If you have a line that says either fglrx or nvidia, you're in good shape. If you get ati or nv, you need to install the proprietary drivers for your card. If you get vesa, i810, or something else, you probably don't have a video card, and will just have to accept lower performance.

如果有 openGL 渲染的显卡,制作复杂的图形会有更好的性能。打开一个终端,运行命令模板:Grep Driver /etc/X11/xorg.conf。如果结果包含 fglrx 或 nvidia,那再好不过了。如果结果有 ati 或 nv ,您需要安装专有的显卡驱动。如果结果是 vesa ,i810 或其他,您可能没有安装显卡,将只有较低的性能。

安装MATLAB

安装MatlabR2008a

安装MatlabR2008a

其它未知版本

MATLAB 的安装脚本不会从一个加载的光驱上运行。Oddly, this is not due to default settings mounting cd-drives with -noexec, but some mystical and poorly understood voodoo. The cure is to copy the disk to your harddrive, and then run the install. To copy the disk, open a terminal and type the following

MATLAB 的安装脚本不会从一个加载的光驱上运行。奇怪的是,这并不是挂载光驱时的默认选项 -noexec 造成的,而是其他令人捉摸不透的原因。解决办法是复制光盘的内容到硬盘,然后运行安装程序。要完成这个操作,请打开终端并运行以下命令:

sudo cp -R /media/cdrom0 /tmp/matlab

一旦复制完毕,在终端输入

sudo sh /tmp/matlab/install_unix.sh

这将加载图形化的安装程序。For your root directory, enter /usr/local/matlab, and agree to make the directory. Then click the box labelled Create symbolic links to MATLAB and mex scripts, and select /usr/local/bin. Continue with the OK buttons until it starts to install. Once it is installed, running the command matlab will launch the MATLAB UI.

你可以使用附加的选项来启动 MATLAB ,在 matlab -option 的格式里。这里有一些常用的选项。

-nodesktop             在一个终端里启动 MATLAB 而没有图形界面 - 加载的非常迅速。
-nosplash              在启动 MATLAB 时不显示启动界面。
-nojvm                 不启动 Java 支持。这也导致 -nodesktop.
-r "command"           启动 MATLAB 并执行给定的命令。
-h                     显示更多选项。

一个例子: matlab -nojvm -nosplash -r "1+1"

丢失cellfun.mexglx (以及其它文件)

如果你在一个安装有 Ubuntu (Breezy Badger) 的 x86 机器安装 Matlab (版本 7.0.1.24704 (R14) Service Pack 1),有可能会遇到文件 /etc/libc.so.6 的权限问题。这一般是由于用户没有执行权限,而这又是一些脚本所需要的。当一些脚本(安装和开始脚本)尝试查询libc文件的版本的时候,得到的返回值是empty strings。由于这个原因,一些meglx文件没有被安装;同时当matlab启动时,脚本 ${matlab_dir}/bin/util/oscheck.sh的运行会报错:

/opt/matlab/bin/util/oscheck.sh: line 134: /lib/libc.so.6: Permission denied

文件 ${matlab_dir}/toolbox/matlab/datatypes/cellfun.mexglx 没有安装,这将导致在执行简单命令,比如 ls ,的时候出现问题,例如,

>> ls
??? Attempt to execute SCRIPT cellfun as a function.
Error in ==> iscellstr at 13
res = cellfun('isclass',s,'char');
Error in ==> ls at 16
if iscellstr(varargin)

解决这个问题的办法之一是修改脚本 ${matlab_dir}/bin/util/oscheck.sh 和脚本 ${matlab_install_cd}/install 的两行。

${matlab_install_cd}/install 的697行

ver=`strings /lib/libc.so.6 | head -n 1 | sed -e "s/<sup>[</sup>0-9]*//" -e "s/[ ,].*$//"`

${matlab_dir}/bin/util/oscheck.sh 的134行

ver=`/lib/libc.so.6 | head -n 1 | sed -e "s/<sup>[</sup>0-9]*//" -e "s/[ ,].*$//"`

应当使用下列行来替代

ver=`strings /lib/libc.so.6 | grep "GNU C Library" | sed -e "s/<sup>[</sup>0-9]*//" -e "s/[ ,].*$//"`

对于一个 64 位机器,你应当必须编辑 install 的 713 行和 oscheck.sh 脚本的 150 行, respectively. 这些改变和上面描述的是相同的。

The need to edit an install script will necessitate copying the CD to the hard disk as described in a previous section. A more detailed explanation can be found here. This could help explain other problems with other missing or improperly linked .mexglx files.

符号工具不工作

To see if you're affected by this, either look at your MATLAB box and see if it says R13, or run the command vpa(pi,64). If it gives you the following error message

Unable to load mex file: /usr/local/matlab/toolbox/symbolic/maplemex.mexglx.
/usr/local/matlab/bin/glnx86/libmaple.so: symbol errno, version GLIBC_2.0 not defined in file libc.so.6 with link time reference
??? Invalid MEX-file

You have the infamamously annoying NPTL bug. First, open up your text editor to the script which launches MATLAB. A good way to do that is

sudo gedit `which matlab`

Note the ` is not '. 找到不是#开头的第一行(大概在 136行左右)。 在这行前面加上一行代码: export LD_ASSUME_KERNEL=2.4.1, 之后你的文件形式应该如下:

#<u></u><u></u><u></u><u></u><u></u><u></u><u></u><u></u><u></u><u></u><u></u><u></u><u></u><u></u><u></u><u></u><u></u><u></u>__
#
export LD_ASSUME_KERNEL=2.4.1
arg0_=$0
#
# Temporary file that hold MATLABPATH code from .matlab6rc.sh file.
#
temp_file=/tmp/$$a
#
trap "rm -f $temp_file; exit 1" 1 2 3

保存并关闭编辑器, 再尝试一次前面的操作。 If you want to double check that it worked, at the MATLAB command prompt run getenv('LD_ASSUME_KERNEL'), if it says 2.4.1 you're set.

OpenGL 和 MATLAB

If you are having problems with openGL doing stupid things like rendering surface patches in the wrong order, or getting errors saying that OpenGL not available, using ZBuffer, and are using a version older than R14SP2, then you might have to do a bit of work to get things running right. The source for most of the thinking in this part is MathWorks

Once you've gotten the MATLAB desktop up and running, at the prompt enter the opengl info command, as in the following example:

>> opengl info
Version        = 2.0.0 NVIDIA 76.64
Vendor         = NVIDIA Corporation
Renderer       = GeForce FX 5200/PCI/SSE2
MaxTextureSize = 4096
Extensions     = GL_ARB_depth_texture GL_ARB_fragment_program GL_ARB_fragment_program_shadow ...

你的结果应当是和上面不一样的,但最重要的部分是 Renderer 这一行。在我的例子中,它显示了使用的显卡的名称。如果你使用了软件渲染,那一行就会显示 Mesa X11 。如果你有一个显卡,但没有得到硬件加速,你也许会需要使用 manufacturers 驱动,这个问题已经有很多相关文档了。

如果它不是你的显卡的驱动,那么打开一个终端输入下列命令:

ldd /usr/local/matlab/bin/glnx86/glren.so

命令的输出将展示你 openGL 的库文件是否都在合适的位置。这里是一个工作配置的输出示例。

$ldd /usr/local/matlab/bin/glnx86/glren.so
libmx.so => not found
libut.so => not found
libmwudd.so => not found
libmwservices.so => not found
libGL.so => /usr/lib/libGL.so (0xb7f45000)
libGLU.so => /usr/X11R6/lib/libGLU.so (0xb7ecf000)
libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0xb7ec2000)
libXp.so.6 => /usr/X11R6/lib/libXp.so.6 (0xb7eba000)
libXt.so.6 => /usr/X11R6/lib/libXt.so.6 (0xb7e6a000)
libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0xb7da5000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7c78000)
libGLcore.so.1 => /usr/lib/libGLcore.so.1 (0xb750f000)
libnvidia-tls.so.1 => /usr/lib/tls/libnvidia-tls.so.1 (0xb750d000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb74ec000)
libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb74e8000)
libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0xb742e000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7423000)
libSM.so.6 => /usr/X11R6/lib/libSM.so.6 (0xb741a000)
libICE.so.6 => /usr/X11R6/lib/libICE.so.6 (0xb7402000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)

如果你丢失了这个清单中的一个重要的库,但它是安装好的,那么你需要为它创建一个链接。让我们看这一行,libGL.so => not found。在一个终端中你要运行下列命令:

cd /usr/local/matlab/sys/opengl/lib/glnx86
dpkg -S libGL.so
ln -s /usr/lib/libGL.so libGL.so

The odds of you having this problem is fairly low if you are using the proper drivers for your videocard. If you cannot find the missing library, try to find and install it using apt-cache search <term>, where <term> is something like libXt.

If things still aren't working well, but do work kinda, the problem is probably MATLAB being silly and not using the right XVisual. We test this by opening up the MATLAB desktop and running the following code

hf=figure;
set(hf,'renderer','opengl');
get(hf,'xvisual')

这将返回一个字符串,例如 0x21 (TrueColor, depth 24, RGB mask 0xff0000 0xff00 0x00ff).。我们使用它来检查 glxinfo,为了确认 MATLAB 不笨。

glxinfo | grep 0x21 | awk '{print $15}'

如果它返回了 24 (和 MATLAB 给出的深度相匹配),那么一切都是正常的。如果它是 0 ,你需要为 XVisual 找另外一个值。最简单的方法是使用 glxinfo 。

glxinfo | grep tc | grep y

选择一个最后一列不是 Slow 的行 - 可能是 None ,并且在第 15 列是 24 的行。这是一个示例输出。

0x21 24 tc  0 32  0 r  y  .  8  8  8  0  4 24  0 16 16 16 16  0 0 None
0x23 24 tc  0 32  0 r  y  .  8  8  8  8  4 24  0 16 16 16 16  0 0 None
0x26 24 tc  0 32  0 r  y  .  8  8  8  0  4 24  8 16 16 16 16  0 0 None
0x27 24 tc  0 32  0 r  y  .  8  8  8  8  4 24  8 16 16 16 16  0 0 None
0x2a 24 tc  0 32  0 r  y  .  8  8  8  0  4 16  0 16 16 16 16  0 0 None
0x2b 24 tc  0 32  0 r  y  .  8  8  8  8  4 16  0 16 16 16 16  0 0 None
0x2e 24 tc  0 32  0 r  y  .  8  8  8  0  4  0  0 16 16 16 16  0 0 None
0x2f 24 tc  0 32  0 r  y  .  8  8  8  8  4  0  0 16 16 16 16  0 0 None
0x32 24 tc  0 32  0 r  y  .  8  8  8  0  4 24  0 16 16 16 16  2 1 Ncon
0x33 24 tc  0 32  0 r  y  .  8  8  8  8  4 24  0 16 16 16 16  2 1 Ncon
0x34 24 tc  0 32  0 r  y  .  8  8  8  0  4 24  0 16 16 16 16  4 1 Ncon
0x35 24 tc  0 32  0 r  y  .  8  8  8  8  4 24  0 16 16 16 16  4 1 Ncon
0x3a 24 tc  0 32  0 r  y  .  8  8  8  0  4 24  8 16 16 16 16  2 1 Ncon
0x3b 24 tc  0 32  0 r  y  .  8  8  8  8  4 24  8 16 16 16 16  2 1 Ncon
0x3c 24 tc  0 32  0 r  y  .  8  8  8  0  4 24  8 16 16 16 16  4 1 Ncon
0x3d 24 tc  0 32  0 r  y  .  8  8  8  8  4 24  8 16 16 16 16  4 1 Ncon
0x42 24 tc  0 32  0 r  y  .  8  8  8  0  4 16  0 16 16 16 16  2 1 Ncon
0x43 24 tc  0 32  0 r  y  .  8  8  8  8  4 16  0 16 16 16 16  2 1 Ncon
0x44 24 tc  0 32  0 r  y  .  8  8  8  0  4 16  0 16 16 16 16  4 1 Ncon
0x45 24 tc  0 32  0 r  y  .  8  8  8  8  4 16  0 16 16 16 16  4 1 Ncon

如果我们选择 0x26 来为 XVisual 使用。在 MATLAB 里设定,只需要运行

set(0,'defaultfigurexvisual','0x26');

添加到你的 startup.m 文件里,你将得到一个全新的 openGL 图像。