Matlab的常见问题

Matlab的常见问题

Matlab的常见问题
>************************************************************************<

=================================== - [返回]
1).Matlab 6.X在Windows 2000/XP上无法启动
:#highsun,2001/3/2, SMTH/NewSoftware #

MathWorks的解决办法虽然是针对繁体中文系统的,我试过在简体
中文系统下一样可以用。

http://www.mathworks.com/support/solutions/data/26985.shtml
http://www.mathworks.com/support/solutions/data/26990.shtml

Solution Number: 26990
Date Last Modified: 2001-01-30
Product: MATLAB 6.0 ==> Current Version
Platform: Windows

Problem Description

Why do I encounter problems when running MATLAB 6.0 (R12) on Hebrew
or
Traditional Chinese (Taiwan) Windows? I try to start MATLAB but after
the splash screen disappears, MATLAB exits.
PLEASE NOTE: This solution only applies to MATLAB 6.0. If you have a
similar problem with MATLAB 5.0 or the Student Edition of MATLAB 5.0,
see solution 7213.

Solution:

This problem is caused by a bug in one of the font properties files
we ship with MATLAB. The font.properties file is used by Java to map
the standard Java font names to system fonts for a particular
However, we made a few assumptions that do not hold for the Hebrew or
language operating system. Traditional Chinese Windows, causing
We have created a fixed version of the mwt.jar file that you can use
this problem. correct this. To use the fix, first rename your mwt.jar
to file as mwt.old. This file is found in the $MATLAB\java\jar
directory, where $MATLAB is your MATLAB root directory. Then
download the newer mwt.jar file from:

ftp://ftp.mathworks.com/pub/tech-support/solutions/s26990

and place it in your $MATLAB\java\jar directrory. Then restart
MATLAB;this should correct the problem you're seeing.

=================================== - [返回]
3).如何在给定句柄的axis里绘图?
plot(data,'parent',haxis);
或者
hbar=bar(data);
set(hbar,'parent',haxis);


=================================== - [返回]
4).由Matlab符号运算得到的公式怎么才能将数据代进去运算?

使用subs(),或先将值赋予一个符号变量,然后用eval()


=================================== - [返回]
5).在Matlab中如何求最值点?如何求一维数组的极值?

最值:
一维或多维数组最值用max(data(:))
如果想返回最值所在的位置,用[Y,I]=max(data)

极值:
data是你的数据,
find(diff(sign(diff(data)))==-2)+1
找到极大值的位置

find(diff(sign(diff(data)))==2)+1
找到极小值的位置

data(find(diff(sign(diff(data)))==-2)+1)和
data(find(diff(sign(diff(data)))==2)+1)
返回的是极大值和极小值


=================================== - [返回]
6).Matlab中如何作线性拟合/线性回归/多元线性回归?

即用y=a*x+b来拟合一组数据{{x1,y1},{x2,y2}…{xn,yn}}
matlab中使用polyfit
x=data(:,1);
y=data(:,2);
p=polyfit(x,y,1);
p(1)为斜率a,p(2)为截距b

多元线性回归即用y=a1*x1+a2*x2+..+am*xm来拟合数据点{x1i,x2i,…xmi,yi}
(i=1~n)

|x11,x21,…xm1|
A=|x12,x22,…xm2|
|…………… |
|x1n,x2n,…xmn|

Y={y1,y2,y3,…,yn}'

则系数{a1,a2,…,am}'=pinv(A)*Y
在matlab中使用
coeff=A\Y
则可以得到最小二乘意义上的拟合系数


=================================== - [返回]
7).Matlab中如何作圆回归?

Q5.5: How can I fit a circle to a set of XY data?
=================================================

An elegant chunk of code to perform least-squares circle fitting
was written by Bucher Izhak and has been floating around the
newgroup for some time. The first reference to it that I can
find is in:

function [xc,yc,R,a] = circfit(x,y)
%CIRCFIT Fits a circle in x,y plane
%
% [XC, YC, R, A] = CIRCFIT(X,Y)
% Result is center point (yc,xc) and radius R.A is an
% optional output describing the circle's equation:
%
% x^2+y^2+a(1)*x+a(2)*y+a(3)=0

% by Bucher izhak 25/oct/1991

n=length(x); xx=x.*x; yy=y.*y; xy=x.*y;
A=[sum(x) sum(y) n;sum(xy) sum(yy)...
sum(y);sum(xx) sum(xy) sum(x)];
B=[-sum(xx+yy) ; -sum(xx.*y+yy.*y) ; -sum(xx.*x+xy.*y)];
a=A\B;
xc = -.5*a(1);
yc = -.5*a(2);
R = sqrt((a(1)^2+a(2)^2)/4-a(3));

Tom Davis provided a more sophisticated approach that works
for more cases in and Code included.


=================================== - [返回]
8).Matlab中如何绘制箭头?

http://www.mathworks.com/matlabcentral/fileexchange/index.jsp
2-D Plotting and Graphics中查找arrow.m,或者
http://www.mathworks.com/matlabcentral/spotlight/arrows.shtml
http://www.math.umd.edu/~jec/matcomp/matcompmfiles/mfiles.html


=================================== - [返回]
9).Matlab中如何作二维数据的插值?

对于一维、二维、三维规则数据点阵使用interp1/interp2/interp3,
二维、三维非规则数据用griddata/griddata3


=================================== - [返回]
10).Matlab中如何绘制三维数据阵?

如果使用matlab,打开帮助窗口,在目录树上找到
MATLAB\Using Matlab\
3-D Visualization: Volume Visualization Techniques

如果图形复杂,建议使用Tecplot,参见Tecplot手册中数据格式,将你
的三维数据读入Tecplot,双击zone,可以设置mesh/contour/surface
transparency等。

在Field菜单中有3D Iso-surface Details和3D Slice Details,可以绘制等值
面和任意平面的截面图。


=================================== - [返回]
11).Matlab中如何注解一大段代码?

注释大段代码选中代码,Ctrl+R;取消注释,选中代码,Ctrl+T。
或者用Edit菜单或者右键弹出中的注释。


if(0)
大段的代码
end


=================================== - [返回]
12).Matlab中如何计算程序运行的时间?
tic
your_code;
toc
或者使用
t=cputime;
your_operation;
cputime-t


=================================== - [返回]
13).Matlab中如何改变默认的工作路径?

编辑一个startup.m文件,其中cd yourpath
或者在X:\matlab\toolbox\local\matlabrc.m的最后添加cd yourpath
参见:
http://www.mathworks.com/support/solutions/data/25164.shtml


=================================== - [返回]
14).Matlab如何改变默认的图形字体?

编辑一个startup.m文件,其中
set(0,'DefaultObjectnamePropertyName',Value)
或者在X:\matlab\toolbox\local\matlabrc.m的最后添加
set(0,'DefaultObjectnamePropertyName',Value)


=================================== - [返回]
15).如何在Matlab中实现交互操作?

如果只在命令窗口进行交互操作,请参见demo中的例子,主要是
通过input命令和pause/clear/disp等实现的,还有一些窗口资源可以使
用:
uigetfile,uiputfile,uiwait,uisetcolor,uisetfont, uiopen,uisave
inputdlg,msgbox,helpdlg,questdlg,warndlg,errordlg


=================================== - [返回]
16).Matlab中为什么只能在小数点后显示四位?

用format命令来改变命令窗口数字的显示格式和精度,但不会影
响matlab的计算精度,matlab的矩阵运算默认都是双精度浮点型运算。



=================================== - [返回]
17).Matlab如何在命令窗口按照格式输出?
fprintf(1,"your_format_string",var1,var2,…);


=================================== - [返回]
18).如何在Matlab中画隐函数曲线?

http://www.mathworks.com/matlabcentral/fileexchange/index.jsp
查找implicit,会找到一个Arthur Jutan写的implot.m
Mathematica中绘制隐函数用ImplicitPlot[]
或者ImplicitPlot3D[]
Maple中为implicitplot(),implicitplot3d()
参见
http://engineering.dartmouth.edu/~fangq/MATH/download/source/
ImplicitPlot3D.htm


=================================== - [返回]
19).Matlab中什么函数可以删除矩阵的某一行或列?



A(j,:)=[]; %删除A的第j行
A(:,i)=[]; %删除A的第i列


=================================== - [返回]
20).Matlab中能开的最大数组是由什么决定的?

I have had similar problems. Below is an explanation I received from
Ian Boyd
from Mathworks (just giving credit where credit is due) that explains
what's happening. You solution is to run matlab with the -nojvm mode.
"The heap memory system in JAVA consists of data and handle elements.
When you allocate a variable you get a handle and data. As long as
data has an associated handle, the JVM considers it valid and
will not clean it up.

However, when you call the clear function in MATLAB, all handles are
destroyed, and the data associated is now invalid. This means that
the JAVA engine can free up that data (garbage collection), but does
not mean that it will clean it up at that moment.

Calling the PACK command encourages JAVA to run the garbage collector
and de-fragment the memory. But it does not force it to (This is part
of the JAVA design). Even though the memory is 'freed' on the heap,
it is not actually free to the OS, it is only free to the JVM. Here
is one way to think of it:

[MATLAB]
[JAVA]
[OS]
MATLAB runs on JAVA (virtual machine), and Java runs on the OS
(physical machine). So when MATLAB is running in JAVA mode memory
allocations are requested from the JRE, not the OS.

One problem you may be running into is that the default maximum
JAVA heap size is relatively low ( <= 64 MB), so that is all the
memory one session of MATLAB will ever get on your system.

The good news is that you can increase this value. You will need
to create a java.opts file in $MATLAB/bin/$ARCH (or in the current
directory when you start MATLAB) and put the following command:

%%%BEGIN CODE%%%
maxHeapSize = 268435456
%%%END CODE%%%

This will give you 256MB of JVM memory and you can adjust the
parameter as needed.

Note: $MATLAB is the root directory and $ARCH is your system
architecture. This solution works on Windows as well as Solaris,
Linux,Alpha, and SGI. A similar operation is possible on IBM and
HPUX, but with a different syntax.

For the 1.1.8 JVM (Windows, Linux, Solaris, Alpha, SGI) our
defaults are:

minHeapSize = 16000000
maxHeapSize = 64000000

These are the structure field names in that correspond to
-ms and -mx, and the settings above are roughly 16MB and 64MB.
To investigate the Java heap a bit, ask via the following:
>> java.lang.Runtime.getRuntime.totalMemory
>> java.lang.Runtime.getRuntime.freeMemory

When the free memory hits zero, Java will double the heap size
(up to the maximum setting).

If you choose to run without Java, you will remove the overhead
of the middle man, but you will also lose some MATLAB functionality
(mostly graphics and the Editor). You will still have most
of the computational power though.

Without JAVA, memory management will come directly from the OS,
and a CLEAR operation will result in memory being freed back to
the OS.


=================================== - [返回]
21).如何在Matlab中添加新的工具箱?

如果是Matlab安装光盘上的工具箱,重新执行安装程序,选中即可。
如果是单独下载的工具箱,一般情况下仅需要把新的工具箱解压到某
个目录,然后用addpath(对于多个目录的使用genpath()或者pathtool添
加工具箱的路径,然后用which newtoolbox_command.m来检验是否可
以访问。如果能够显示新设置的路径,则表明该工具箱可以使用了。
具体请看工具箱自己代的README文件。



=================================== - [返回]
22))如何读写Matlab的.mat文件?

文件结构参见:
http://www.mathworks.de/access/helpdesk/help/pdf_doc/matlab/
matfile_format.pdf
http://www.mathworks.com/support/solutions/data/8757.shtml
ftp://ftp.mathworks.com/pub/tech-support/solutions/s8757/
readmemat.txt

建议使用matlab自己提供的函数来读写简单安全,或者参考:
http://engineering.dartmouth.edu/~fangq/MATH/download/
source/mat_file.txt
来自matlab的c math library


=================================== - [返回]
23).如何得到contour线上的坐标点?


lcount=5;
[c,h]=contour(peaks,lcount);
x=get(h,'xdata');
y=get(h,'ydata');

这里得到的x和y都是cell数组,用x{1}/y{1}来得到每条线上的坐标对,
注意,每条线的最后一个数据是NaN


=================================== - [返回]
24).如何将Matlab绘制的三维网格图帖到word里?

如果需要位图,好处是所见即所得,坏处是图像精度差,不能放缩:
1.用拷屏 Alt+PrintScreen
2.在图形窗口菜单Edit\Copy Options….\选择Bitmap,可以
选择透明背景,然后Edit\Copy Figure

如果需要拷贝矢量图:
在图形窗口菜单Edit\Copy Options….\选择Metafile,然后
Edit\Copy Figure,在Word中粘贴

经常地,按照Metafile方式粘贴的图片曲线会出现锯齿,最好的方式是
使用eps文件:
1.将需要拷贝的图作为当前窗口
2.再转换到matlab命令窗口,print -deps filename.eps
3.-deps还可以用depsc,deps2,depsc2
4.在word中插入图片,选中该eps,如果是word 2000以前版本
,不会显示图片内容,但可以打印,word XP即可显示,又可打印。
5.如果不满意,可以在word中双击编辑,如果安装有Adobe
Illustrator等矢量图像编辑软件,也可以进行编辑。



=================================== - [返回]
25).请问可以查看Matlab中函数的源代码吗?


Matlab除了buildin函数和mex/dll文件看不到原码,其他如工具箱等都可
以直接看到代码,首先确认该文件安装在matlab中,即which
filename.m存在,然后可以edit filename.m


=================================== - [返回]
26).Matlab有没有求矩阵行数/列数/维数的函数?

ndims(A)返回A的维数
size(A)返回A各个维的最大元素个数
length(A)返回max(size(A))
[m,n]=size(A)如果A是二维数组,返回行数和列数
nnz(A)返回A中非0元素的个数


=================================== - [返回]
27).Matlab中如何中断运算?

在命令窗口按Ctrl+C,在UNIX/LINUX会立即中断运算,在Windows可
能由于操作系统的原因,有时会出现死机和等待的情况。


=================================== - [返回]
28).Matlab中有没有画圆或椭圆的函数?

没有,Matlab没有提供直接绘圆的图元函数,需要自己写代码,其实
就两句:
sita=0:pi/20:2*pi;
plot(r*cos(sita),r*sin(sita)); %半径为r的圆

plot(a*cos(sita+fi),b *sin(sita+fi)); %椭圆

如果是单位圆,可以使用rectangle('Curvature', [1 1])


=================================== - [返回]
29).Matlab下如何定义整形
Matlab默认的矩阵数据结构都是双精度浮点型,即64位来表示一个数
字,大多数的函数和操作都定义在double数据结构,如果你需要
把double的数据转换为整形,然后再参与运算,需要使用
double(int32(x))或者floor/round/ceil等函数

如果为了节省内存,只进行赋值、打印等简单操作,可以参
见uint8/uint16/uint32命令的帮助


=================================== - [返回]
30).Matlab如何产生均匀分布的白噪声?

help rand 均匀分布百噪声
help randn高斯分布百噪声


=================================== - [返回]
31).在Matlab中debug的时候能否跟踪变量的?

可以,如果使用medit,设置断点后可以用鼠标移到所看的变量上,显
示当前的值,或者在命令窗口打该变量名直接回车。如果在代码中实
现调试断点等功能,参
见dbstop,dbcont,dbstep,dbclear,dbtype,dbstack,dbup,dbdown,dbstatus,
dbquit


=================================== - [返回]
32).请问在Matlab中怎样输入特殊符号啊或者上标、下标?
matlab的text/title/xlabel/ylabel对象支持简单的TeX排版语法,如希腊字
母,上下标等例如
text(0.5,0.5,'\alpha^\beta_2');


=================================== - [返回]
33).Matlab中如何后台运行一个DOS程序?

这里是一个后台执行一个需要外部输入的DOS命令的例子,需要的输
入实事先都写在同目录下的input.txt文件中:

dos('myexe < input.txt &')


=================================== - [返回]
34).Matlab如何加载输入文件(批处理模式) ?
PC上可以使用matlab /r参数来在matlab启动的时候直接加载运行m文件
,在UNIX上,使用
matlab < MyMFile > MyOutputFile
来外部执行MyMFile,

以上执行方式都可以通过脚本文件实现批处理


=================================== - [返回]
35).Matlab如何启动时执行规定的文件?
参见上一个问题的回答


=================================== - [返回]
36).如何在Matlab GUI中使用图形背景?
这是一个简单的例子:

[A,map]=imread('yourimg.gif');

imagesc(A)
colormap(map)
set(gca,'position',[0 0 1 1])
axis off

ax2=axes('position',[0.2,0.2,0.6,0.6]);
plot(rand(1,10),'parent',ax2);
set(ax2,'color','none')



=================================== - [返回]
37).大量数据点Matlab绘图为什么很慢?

1.首先看能否用已有函数对整个矩阵绘图,比
如mesh/plot3/trimesh等
2.如果必须一点一点/或者一条线一条线的添加,最好作如下
设置:
doublebuffer=on
erasemode=none
backingstore=off
renderer=opengl
以及参考MathWorks对于高速绘图的tips:
http://www.mathworks.com/support/tech-notes/v5/1200/1203.shtml,

=================================== - [返回]
38).Matlab中如何求解广义积分?即积分限到有无穷的或者有奇异点的积分(瑕积分)?
Matlab的quad/quad8只能作定积分,广义积分需要自己来写程序逼近,
流程大概如下:

1.设定收敛限epsi
2.把为inf/-inf或者歧义点的积分限设置为一个初始值,k=1
3.计算定积分Q(k)
4.然后朝着inf/-inf或者歧义点移动一个步长,然后计算定积分
Q(k+1)
5.判断(abs(Q(k+1)-Q(k))

Mathematica中可以使用NIntegrate[],对于无穷振荡的函数,可以使用Method->
QuasiMonteCarlo或者Oscillatory]


=================================== - [返回]
39).为什么我的Matlab程序这么慢?
我们工学院的收发室的门上贴着一张小纸条,写的是
"Our policy is always blaming the computer"

大多数的人在遇到问题的时候,总是责备计算机如何如何,别人如何
如何,其实,最最主要的因素是在于自己。

一个程序运行快慢,有很多因素决定,最主要的是算法,简炼而优美
的的数学公式胜过100遍的优化。能从算法上改进,才能比别人有根
本的优势。计算机也很重要,以前我总把自己用的PC看成万能的加
以崇拜,对UNIX嗤之以鼻,结果当自己真正开始算起来,才知道差
别有多大。搞大型数值计算的,没有好的工作站或者并行系统,就输
在了起跑线上了。然后是程序的优化,看看变量是否占用太多内存,
看看是否有功能重复的模块或者计算,经常的是用牺牲内存来换取速
度,具体取舍,具体需要来决定。用profile看看哪些语句占用时间最
多,然后把核心部分进行优化。

如果是使用Matlab,使用vectorization和矩阵整体操作的代码要比大量
的for循环快很多,eval/inline函数如果出现在核心循环,也会让速度下
降几时倍的。


=================================== - [返回]
40)..Matlab中如何作非线性回归?


请参考
http://www.mathworks.com/support/solutions/data/10652.shtml

matlab默认只提供了多项式拟合的函数polyfit,对于其他稍微简单
一点的拟合,如标准的指数、对数、高阶多项式拟合,都有解析公式,参见:
http://mathworld.wolfram.com/LeastSquaresFitting.html
对于更加复杂的非线性函数,建议使用Mathematica或者DataFit

Mathematica中提供了Fit[],以及
<< Statistics`NonlinearFit`
NonlinearFit[],NonlinearRegress[]
可以拟合任意复杂的表达式。

DataFit可以自定义拟合模型,适用于复杂系统的拟合。


=================================== - [返回]
41)..Matlab中为什么我对m文件、simulink模块,mat文件的修改不起作用呢?

检查Matlab路径中是否有与你的m文件、mdl文件或者mat文件同名的m文件、
mdl文件或者mat文件。Matlab执行搜索到的第一个文件。

=================================== - [返回]
42).Matlab中,函数里面怎样使用基本工作空间中的变量?
为什么inline函数不能使用外面的变量?

函数只能存取它自己的工作空间中的变量。要在函数之间,或者函数与基本
工作空间之间传递数值,尝试以下方法:
1、使用全局变量,用global定义全局变量
2、使用evalin:
evalin('base','v=1;'); %在基本工作空间中执行命令:v=1;
evalin('caller','v=1;');%在调用该函数的函数的工作空间中
执行命令:v=1;
3、参数传递
4、使用assignin:
assignin('base','v',v); %将v赋给基本工作空间中的变量v;
assignin('caller','v',v); %将v赋给调用者工作空间中的变量v;
inline函数里面只能出现函数和参数,要传递一个可变系数,需要用evalin。
如:fzero('f(evalin(''base'',''x1(i)''),x3)',求解区间)

=================================== - [返回]
43).怎样在Simulink中调用m文件?
函数m文件可以使用Function & Tables中的Fcn模块。如果有多个输入,
用Mux组合成一个向量,然后在Fcn模块的Expression填
MyFunction(u(1),u(2))"。如果有多个输出,用Demux分解成多个标量。


=================================== - [返回]
44).Matlab中怎样进行数制转换?
参见:hex2dec,oct2dec,bin2dec,dec2bin,dec2oct,dec2hex.

=================================== - [返回]
45).matlab中的*.p是什么文件?怎么用?

p文件是pre-parsed的缩写,即matlab在第一次运行某m文件时,matlab把该
文件先编译成一种matlab的pseudo-code,当你再次运行该m文件时,节省了
parse的时间。

p文件可以离开m文件单独运行

:#Mike Robbins (michael.robbins@us.cibc.com),2001/04/20,comp.soft-sys.matlab#

在matlab中用pcode('yourfilename')来生成p文件

=================================== - [返回]
46).在Matlab中有goto语句吗?
matlab中没有提供goto,因为结构化程序设计不推荐使用goto,但在matlab
中,goto的功能可以部分用结构化的异常处理机制来实现,比如从多重循环
中跳出,具体代码为:

try
for i=1:10
for j=1:10
for k=1:10
do_something;
if(jump_condition)
errorid=-2;
error('I want to get out!');
end
end
end
end
catch
fprintf(1,'catch error:%d',errorid);
end

=================================== - [返回]
47).请问matlab6.X的那个matlab server是做什么的?(matlab开机运行问题)

如果你在安装matlab时选择了web server的话,在每次重新启动后系统
进程中就会出现matlab/matlabserver两个进程,如果你不需要使用
matlab webserver服务的话,建议在安装时不要选择web server,
如果已经安装的话,可以在"控制面板->管理工具->服务"中找到
matlab webserver,然后把它disable掉。

=================================== - [返回]
48).Matlab中如何用鼠标取得坐标?

matlab中用ginput来取得图像上的一点。注意:image()/imagesc()对象
的y轴是和一般图的y轴反的。

如果复杂的话,可以在ButtonDownFcn中get(0,'PointerLocation')
或者get(gcf,'Position');

=================================== - [返回]
49).Matlab中有阶乘函数吗?
matlab没有提供直接的阶乘函数,但可以用prod(1:n)来求n!
用prod(1:2:2n-1)或者prod(2:2:2n)来求解n!!

=================================== - [返回]
50)..怎样才能把Maltab学精?

"带着问题学,活学活用,学用结合,急用先学,立竿见影,
在'用'字上狠下功夫。"

=================================== - [返回]
51)..Matlab如何计算大阶乘?
如果只需要大致的值,取log10,
计算出result=log10(1000!)=log10(1)+log10(2)+...log10(1000)
然后求10^result=10^result的小数部分*10^result的整数部分


=================================== - [返回]
52)..Matlab中怎样求变上限二重积分?

对于解析函数,用两次int即可。
如求x+y在0[返回]
53)..用符号积分算出来Ei是什么意思,怎样求值?

Ei是maple中的指数积分函数,表示exp(-x*t)/t^n对t从1到正无穷大的积分。
Ei(n,x) = int(exp(-x*t)/t^n, t=1..infinity)
用命令“mhelp Ei”可以查看详细说明;用符号计算得到的不明白的函数都可以通过
mhelp命令得到帮助。
求Ei(1,2)可以用maple命令得到:str2num(maple('evalf(Ei(1,2))'))。

=================================== - [返回]
54)..Maltab中使用\n换行在notepad中显示为小黑块,为什么?(Randy Poe)

换行和回车是不同的,而且在不同的操作系统,解释也不相同。
\n一般会操作系统被翻译成"行的结束",即LF(Line-Feed)
\r会被翻译成"回车",即CR(Cariage-Return)
对于文本文件的新行,在UNIX上,一般用\n(LF)来表示,Mac上用\r(CR)来表示,
Windows上是用\n\r(CR-LF)来表示。

所以在matlab中使用\n来写回车,在windows上打开会出现小方块。如果想
避免这种情况,打开文件时使用t参数:

fid = fopen('myfile.dat','wt');

=================================== - [返回]
55)..Matlab中能开多大数组?(Steven Lord)

使用computer命令:
[C,MAXSIZE] = computer

=================================== - [返回]
56)..如何使用整型矩阵来节省内存?(Duane Hanselman)

如下方法无需先生成一个double的数组,然后转换为int8

>> rc=[3 4] % row and column sizes
>> a(prod(rc))=int8(0) % example using int8
>> class(a) % they are all int8s
>> reshape(a,rc) % make it the size you want

同时也可以使用repmat来实现上述功能:

>> repmat(int8(0),rc)


=================================== - [返回]
57).Matlab在P4芯片上无法启动的解决方案

如果不想安装补丁,只能使用matlab -nojvm的形式启动
matlab,否则需要参照如下页面的解决方案来安装补丁:
http://groups.google.com/groups? ... ;oe=UTF-8&selm=
NQ8a9.6835%24ob2.611653%40newsread1.prod.itd.earthlink.net
http://www.mathworks.com/support/solutions/data/27293.shtml

=================================== - [返回]
58).如何求解对离散点的最优椭圆拟合?(Andrew Fitzgibbon, et al)
:#Authors: Andrew Fitzgibbon, Maurizio Pilu, Bob Fisher
"Direct Least Squares Fitting of Ellipses", IEEE T-PAMI, 1999#

http://bbs.dartmouth.edu/~fangq/MATH/Source/fitellipse.m

=================================== - [返回]
59).Matlab/Mathematica中如何中断当前运算?(FangQ)

Mathematica中使用: Alt+./Alt+,
Matlab中使用: Ctrl+C

=================================== - [返回]
60)).Matlab/Mathematica中如何检查括号匹配?(FangQ)

Mathematica中使用: Ctrl+.
Matlab editor中使用: Ctrl+B

=================================== - [返回]
61)..Matlab的GUI中为何无法使用uicontrol的句柄?(FangQ)

如果你在执行GUI时出现"handles not defined"的错误时,
打开GUIDE,把figure的HandleVisibility设置为on或者callback,
则你可以在各个callback中直接使用handles,而不用声明global

例如:

dat=get(handles.figure1,'userdata');
dat2=fliplr(dat);
se(handles.edit1,'userdata');

=================================== - [返回]
62)..Matlab中如何把向量拓展成矩阵?(Zealous/FangQ)

可以使用repmat(),例如: repmat([1,2,3]',1,5)
或者使用kron(),例如: kron([1 2 3]',ones(1,5))

=================================== - [返回]
63)..Matlab的GUI中的按钮如何在运行时移动及改变大小?(FangQ)
使用selectmoveresize函数,例如:

figure
h=uicontrol('style','pushbutton');
set(h,'ButtonDownFcn',...
'selectmoveresize;set(h,''selected'',''off'')',...
'Enable','inactive')

=================================== - [返回]
64)..Matlab如何求解维数巨大的稀疏矩阵方程?(FangQ)
:#FangQ(Qianqian.Fang@dartmouth),2002/11/19,BigGreen/MathTools#

Matlab提供了非常丰富的迭代型矩阵求解器,方法包括CG,BiCG,BiCGSTAB,
CGS,GMRES,LSQR,MINRES,P-CG,QMR,SYMMLQ等,为了加快矩阵求解速度,还
提供了两个Preconditioner函数:luinc(不完全LU分解),和cholinc(不完全
Cholesky分解)。下面是一个使用GMRES求解方程Amat*x=rhs的一个简单例子:

[L2,U2] = luinc(Amat,1e-3);
tic
x=gmres(Amat,rhs,[],1e-6,100,L2,U2);
toc
MATLABCAE科学计算及数学建模

Matlab的常见问题的评论2条

  • malong
    0
    48)Matlab中如何用鼠标取得坐标?<BR>:#FangQ(Qianqian.Fang@Dartmouth.Edu), 2002/7/23. BigGreen/en_Matlab#<BR><BR>matlab中用ginput来取得图像上的一点。注意:image()/imagesc()对象<BR>的y轴是和一般图的y轴反的。<BR><BR>如果复杂的话,可以在ButtonDownFcn中get(0,'PointerLocation')<BR><BR>===================================<BR>49)Matlab中有阶乘函数吗?<BR>:#FangQ(Qianqian.Fang@Dartmouth.Edu), 2002/7/23. BigGreen/en_Matlab#<BR><BR>matlab没有提供直接的阶乘函数,但可以用prod(1:n)来求n!<BR>用prod(1:2:2n-1)或者prod(2:2:2n)来求解n!!<BR><BR>===================================<BR>50).怎样才能把Maltab学精?<BR>:#energy(长白山), 2002/9/23. SMTH/MathTools#<BR><BR>"带着问题学,活学活用,学用结合,急用先学,立竿见影,<BR>在'用'字上狠下功夫。"<BR><BR>===================================<BR>51).Matlab如何计算大阶乘?<BR>:#lll, 2002/9/18. SMTH/MathTools#<BR><BR>如果只需要大致的值,取log10,<BR>计算出result=log10(1000!)=log10(1)+log10(2)+...log10(1000)<BR>然后求10^result=10^result的小数部分*10^result的整数部分</SPAN>
  • chxiwj
    0
    谢谢<BR>新手上路<BR>多多指教

Matlab的常见问题的相关案例教程

PARDISO是一个商用的高速的稀疏矩阵线性方程组直接法求解器,其可以用于大型稀疏对称或非对称线性方程组的求解,商用版支持的并行方式包括共享内存,分布式内存和NVIDA的GPU并行。多次实践已经表明,PARDISO求解器具有优秀的性能,在各种稀疏矩阵直接求解器的比较中通常处于第一梯队,其他常见的直接法求解器包括SuiteSparse,MUMPS,SPOOLES等,商用有限元软件COMSOL的官方文
package 她; import java.util.*;//控制镜面输入 import java.util.Random;//随机数 public class t { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.print("please enter a firs
原文标题:Why SYCL: Elephants in the SYCL Room By James Reinders and Michael Wong 摘录自:https://www.hpcwire.com/2022/02/03/why-sycl-elephants-in-the-sycl-room/ Commentary — In the second of a series of guest
在我们使用kei c51创建一个51单片机项目时,会有如下图所示的提示: keil创建新项目时,提示是否添加启动文件 一般情况下,需要选择“是”。当然,也可以选择不加。那么,这个启动文件的作用是什么?什么情况下需要加,什么情况下可以不加? 今天我们就来详细了解一下这个启动文件的内容,看明白这个内容后,我们就会有种恍然大悟的感觉:“哦,原来是这样啊!” 启动代码第一段 ▼以下是启动代码原文第一段:
原文:RISC-V Finds Its Foothold in a Rapidly Evolving Processor Ecosystem 作者:Agam Shah 转载自:https://thenewstack.io/risc-v-finds-its-foothold-in-a-rapidly-evolving-processor-ecosystem/ 以下是正文 But the open s
影响力
粉丝
内容
获赞
收藏
    项目客服
    培训客服
    2 0