Matlab的常見問題

Matlab的常見問題

Matlab的常見問題
>************************************************************************<

=================================== - [返回]
1).Matlab 6.X在Windows 2000/XP上無法啟動(dòng)
:#highsun,2001/3/2, SMTH/NewSoftware #

MathWorks的解決辦法雖然是針對(duì)繁體中文系統(tǒng)的,我試過在簡(jiǎn)體
中文系統(tǒng)下一樣可以用。

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符號(hào)運(yùn)算得到的公式怎么才能將數(shù)據(jù)代進(jìn)去運(yùn)算?

使用subs(),或先將值賦予一個(gè)符號(hào)變量,然后用eval()


=================================== - [返回]
5).在Matlab中如何求最值點(diǎn)?如何求一維數(shù)組的極值?

最值:
一維或多維數(shù)組最值用max(data(:))
如果想返回最值所在的位置,用[Y,I]=max(data)

極值:
data是你的數(shù)據(jù),
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來擬合一組數(shù)據(jù){{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來擬合數(shù)據(jù)點(diǎn){x1i,x2i,…xmi,yi}
(i=1~n)

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

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

則系數(shù){a1,a2,…,am}'=pinv(A)*Y
在matlab中使用
coeff=A\Y
則可以得到最小二乘意義上的擬合系數(shù)


=================================== - [返回]
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中如何作二維數(shù)據(jù)的插值?

對(duì)于一維、二維、三維規(guī)則數(shù)據(jù)點(diǎn)陣使用interp1/interp2/interp3,
二維、三維非規(guī)則數(shù)據(jù)用griddata/griddata3


=================================== - [返回]
10).Matlab中如何繪制三維數(shù)據(jù)陣?

如果使用matlab,打開幫助窗口,在目錄樹上找到
MATLAB\Using Matlab\
3-D Visualization: Volume Visualization Techniques

如果圖形復(fù)雜,建議使用Tecplot,參見Tecplot手冊(cè)中數(shù)據(jù)格式,將你
的三維數(shù)據(jù)讀入Tecplot,雙擊zone,可以設(shè)置mesh/contour/surface
transparency等。

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


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

注釋大段代碼選中代碼,Ctrl+R;取消注釋,選中代碼,Ctrl+T。
或者用Edit菜單或者右鍵彈出中的注釋。


if(0)
大段的代碼
end


=================================== - [返回]
12).Matlab中如何計(jì)算程序運(yùn)行的時(shí)間?
tic
your_code;
toc
或者使用
t=cputime;
your_operation;
cputime-t


=================================== - [返回]
13).Matlab中如何改變默認(rèn)的工作路徑?

編輯一個(gè)startup.m文件,其中cd yourpath
或者在X:\matlab\toolbox\local\matlabrc.m的最后添加cd yourpath
參見:
http://www.mathworks.com/support/solutions/data/25164.shtml


=================================== - [返回]
14).Matlab如何改變默認(rèn)的圖形字體?

編輯一個(gè)startup.m文件,其中
set(0,'DefaultObjectnamePropertyName',Value)
或者在X:\matlab\toolbox\local\matlabrc.m的最后添加
set(0,'DefaultObjectnamePropertyName',Value)


=================================== - [返回]
15).如何在Matlab中實(shí)現(xiàn)交互操作?

如果只在命令窗口進(jìn)行交互操作,請(qǐng)參見demo中的例子,主要是
通過input命令和pause/clear/disp等實(shí)現(xiàn)的,還有一些窗口資源可以使
用:
uigetfile,uiputfile,uiwait,uisetcolor,uisetfont, uiopen,uisave
inputdlg,msgbox,helpdlg,questdlg,warndlg,errordlg


=================================== - [返回]
16).Matlab中為什么只能在小數(shù)點(diǎn)后顯示四位?

用format命令來改變命令窗口數(shù)字的顯示格式和精度,但不會(huì)影
響matlab的計(jì)算精度,matlab的矩陣運(yùn)算默認(rèn)都是雙精度浮點(diǎn)型運(yùn)算。



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


=================================== - [返回]
18).如何在Matlab中畫隱函數(shù)曲線?

http://www.mathworks.com/matlabcentral/fileexchange/index.jsp
查找implicit,會(huì)找到一個(gè)Arthur Jutan寫的implot.m
Mathematica中繪制隱函數(shù)用ImplicitPlot[]
或者ImplicitPlot3D[]
Maple中為implicitplot(),implicitplot3d()
參見
http://engineering.dartmouth.edu/~fangq/MATH/download/source/
ImplicitPlot3D.htm


=================================== - [返回]
19).Matlab中什么函數(shù)可以刪除矩陣的某一行或列?



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


=================================== - [返回]
20).Matlab中能開的最大數(shù)組是由什么決定的?

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安裝光盤上的工具箱,重新執(zhí)行安裝程序,選中即可。
如果是單獨(dú)下載的工具箱,一般情況下僅需要把新的工具箱解壓到某
個(gè)目錄,然后用addpath(對(duì)于多個(gè)目錄的使用genpath()或者pathtool添
加工具箱的路徑,然后用which newtoolbox_command.m來檢驗(yàn)是否可
以訪問。如果能夠顯示新設(shè)置的路徑,則表明該工具箱可以使用了。
具體請(qǐng)看工具箱自己代的README文件。



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

文件結(jié)構(gòu)參見:
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自己提供的函數(shù)來讀寫簡(jiǎn)單安全,或者參考:
http://engineering.dartmouth.edu/~fangq/MATH/download/
source/mat_file.txt
來自matlab的c math library


=================================== - [返回]
23).如何得到contour線上的坐標(biāo)點(diǎn)?


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

這里得到的x和y都是cell數(shù)組,用x{1}/y{1}來得到每條線上的坐標(biāo)對(duì),
注意,每條線的最后一個(gè)數(shù)據(jù)是NaN


=================================== - [返回]
24).如何將Matlab繪制的三維網(wǎng)格圖帖到word里?

如果需要位圖,好處是所見即所得,壞處是圖像精度差,不能放縮:
1.用拷屏 Alt+PrintScreen
2.在圖形窗口菜單Edit\Copy Options….\選擇Bitmap,可以
選擇透明背景,然后Edit\Copy Figure

如果需要拷貝矢量圖:
在圖形窗口菜單Edit\Copy Options….\選擇Metafile,然后
Edit\Copy Figure,在Word中粘貼

經(jīng)常地,按照Metafile方式粘貼的圖片曲線會(huì)出現(xiàn)鋸齒,最好的方式是
使用eps文件:
1.將需要拷貝的圖作為當(dāng)前窗口
2.再轉(zhuǎn)換到matlab命令窗口,print -deps filename.eps
3.-deps還可以用depsc,deps2,depsc2
4.在word中插入圖片,選中該eps,如果是word 2000以前版本
,不會(huì)顯示圖片內(nèi)容,但可以打印,word XP即可顯示,又可打印。
5.如果不滿意,可以在word中雙擊編輯,如果安裝有Adobe
Illustrator等矢量圖像編輯軟件,也可以進(jìn)行編輯。



=================================== - [返回]
25).請(qǐng)問可以查看Matlab中函數(shù)的源代碼嗎?


Matlab除了buildin函數(shù)和mex/dll文件看不到原碼,其他如工具箱等都可
以直接看到代碼,首先確認(rèn)該文件安裝在matlab中,即which
filename.m存在,然后可以edit filename.m


=================================== - [返回]
26).Matlab有沒有求矩陣行數(shù)/列數(shù)/維數(shù)的函數(shù)?

ndims(A)返回A的維數(shù)
size(A)返回A各個(gè)維的最大元素個(gè)數(shù)
length(A)返回max(size(A))
[m,n]=size(A)如果A是二維數(shù)組,返回行數(shù)和列數(shù)
nnz(A)返回A中非0元素的個(gè)數(shù)


=================================== - [返回]
27).Matlab中如何中斷運(yùn)算?

在命令窗口按Ctrl+C,在UNIX/LINUX會(huì)立即中斷運(yùn)算,在Windows可
能由于操作系統(tǒng)的原因,有時(shí)會(huì)出現(xiàn)死機(jī)和等待的情況。


=================================== - [返回]
28).Matlab中有沒有畫圓或橢圓的函數(shù)?

沒有,Matlab沒有提供直接繪圓的圖元函數(shù),需要自己寫代碼,其實(shí)
就兩句:
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默認(rèn)的矩陣數(shù)據(jù)結(jié)構(gòu)都是雙精度浮點(diǎn)型,即64位來表示一個(gè)數(shù)
字,大多數(shù)的函數(shù)和操作都定義在double數(shù)據(jù)結(jié)構(gòu),如果你需要
把double的數(shù)據(jù)轉(zhuǎn)換為整形,然后再參與運(yùn)算,需要使用
double(int32(x))或者floor/round/ceil等函數(shù)

如果為了節(jié)省內(nèi)存,只進(jìn)行賦值、打印等簡(jiǎn)單操作,可以參
見uint8/uint16/uint32命令的幫助


=================================== - [返回]
30).Matlab如何產(chǎn)生均勻分布的白噪聲?

help rand 均勻分布百噪聲
help randn高斯分布百噪聲


=================================== - [返回]
31).在Matlab中debug的時(shí)候能否跟蹤變量的?

可以,如果使用medit,設(shè)置斷點(diǎn)后可以用鼠標(biāo)移到所看的變量上,顯
示當(dāng)前的值,或者在命令窗口打該變量名直接回車。如果在代碼中實(shí)
現(xiàn)調(diào)試斷點(diǎn)等功能,參
見dbstop,dbcont,dbstep,dbclear,dbtype,dbstack,dbup,dbdown,dbstatus,
dbquit


=================================== - [返回]
32).請(qǐng)問在Matlab中怎樣輸入特殊符號(hào)啊或者上標(biāo)、下標(biāo)?
matlab的text/title/xlabel/ylabel對(duì)象支持簡(jiǎn)單的TeX排版語法,如希臘字
母,上下標(biāo)等例如
text(0.5,0.5,'\alpha^\beta_2');


=================================== - [返回]
33).Matlab中如何后臺(tái)運(yùn)行一個(gè)DOS程序?

這里是一個(gè)后臺(tái)執(zhí)行一個(gè)需要外部輸入的DOS命令的例子,需要的輸
入實(shí)事先都寫在同目錄下的input.txt文件中:

dos('myexe < input.txt &')


=================================== - [返回]
34).Matlab如何加載輸入文件(批處理模式) ?
PC上可以使用matlab /r參數(shù)來在matlab啟動(dòng)的時(shí)候直接加載運(yùn)行m文件
,在UNIX上,使用
matlab < MyMFile > MyOutputFile
來外部執(zhí)行MyMFile,

以上執(zhí)行方式都可以通過腳本文件實(shí)現(xiàn)批處理


=================================== - [返回]
35).Matlab如何啟動(dòng)時(shí)執(zhí)行規(guī)定的文件?
參見上一個(gè)問題的回答


=================================== - [返回]
36).如何在Matlab GUI中使用圖形背景?
這是一個(gè)簡(jiǎn)單的例子:

[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).大量數(shù)據(jù)點(diǎn)Matlab繪圖為什么很慢?

1.首先看能否用已有函數(shù)對(duì)整個(gè)矩陣?yán)L圖,比
如mesh/plot3/trimesh等
2.如果必須一點(diǎn)一點(diǎn)/或者一條線一條線的添加,最好作如下
設(shè)置:
doublebuffer=on
erasemode=none
backingstore=off
renderer=opengl
以及參考MathWorks對(duì)于高速繪圖的tips:
http://www.mathworks.com/support/tech-notes/v5/1200/1203.shtml,

=================================== - [返回]
38).Matlab中如何求解廣義積分?即積分限到有無窮的或者有奇異點(diǎn)的積分(瑕積分)?
Matlab的quad/quad8只能作定積分,廣義積分需要自己來寫程序逼近,
流程大概如下:

1.設(shè)定收斂限epsi
2.把為inf/-inf或者歧義點(diǎn)的積分限設(shè)置為一個(gè)初始值,k=1
3.計(jì)算定積分Q(k)
4.然后朝著inf/-inf或者歧義點(diǎn)移動(dòng)一個(gè)步長,然后計(jì)算定積分
Q(k+1)
5.判斷(abs(Q(k+1)-Q(k))

Mathematica中可以使用NIntegrate[],對(duì)于無窮振蕩的函數(shù),可以使用Method->
QuasiMonteCarlo或者Oscillatory]


=================================== - [返回]
39).為什么我的Matlab程序這么慢?
我們工學(xué)院的收發(fā)室的門上貼著一張小紙條,寫的是
"Our policy is always blaming the computer"

大多數(shù)的人在遇到問題的時(shí)候,總是責(zé)備計(jì)算機(jī)如何如何,別人如何
如何,其實(shí),最最主要的因素是在于自己。

一個(gè)程序運(yùn)行快慢,有很多因素決定,最主要的是算法,簡(jiǎn)煉而優(yōu)美
的的數(shù)學(xué)公式勝過100遍的優(yōu)化。能從算法上改進(jìn),才能比別人有根
本的優(yōu)勢(shì)。計(jì)算機(jī)也很重要,以前我總把自己用的PC看成萬能的加
以崇拜,對(duì)UNIX嗤之以鼻,結(jié)果當(dāng)自己真正開始算起來,才知道差
別有多大。搞大型數(shù)值計(jì)算的,沒有好的工作站或者并行系統(tǒng),就輸
在了起跑線上了。然后是程序的優(yōu)化,看看變量是否占用太多內(nèi)存,
看看是否有功能重復(fù)的模塊或者計(jì)算,經(jīng)常的是用犧牲內(nèi)存來換取速
度,具體取舍,具體需要來決定。用profile看看哪些語句占用時(shí)間最
多,然后把核心部分進(jìn)行優(yōu)化。

如果是使用Matlab,使用vectorization和矩陣整體操作的代碼要比大量
的for循環(huán)快很多,eval/inline函數(shù)如果出現(xiàn)在核心循環(huán),也會(huì)讓速度下
降幾時(shí)倍的。


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


請(qǐng)參考
http://www.mathworks.com/support/solutions/data/10652.shtml

matlab默認(rèn)只提供了多項(xiàng)式擬合的函數(shù)polyfit,對(duì)于其他稍微簡(jiǎn)單
一點(diǎn)的擬合,如標(biāo)準(zhǔn)的指數(shù)、對(duì)數(shù)、高階多項(xiàng)式擬合,都有解析公式,參見:
http://mathworld.wolfram.com/LeastSquaresFitting.html
對(duì)于更加復(fù)雜的非線性函數(shù),建議使用Mathematica或者DataFit

Mathematica中提供了Fit[],以及
<< Statistics`NonlinearFit`
NonlinearFit[],NonlinearRegress[]
可以擬合任意復(fù)雜的表達(dá)式。

DataFit可以自定義擬合模型,適用于復(fù)雜系統(tǒng)的擬合。


=================================== - [返回]
41)..Matlab中為什么我對(duì)m文件、simulink模塊,mat文件的修改不起作用呢?

檢查Matlab路徑中是否有與你的m文件、mdl文件或者mat文件同名的m文件、
mdl文件或者mat文件。Matlab執(zhí)行搜索到的第一個(gè)文件。

=================================== - [返回]
42).Matlab中,函數(shù)里面怎樣使用基本工作空間中的變量?
為什么inline函數(shù)不能使用外面的變量?

函數(shù)只能存取它自己的工作空間中的變量。要在函數(shù)之間,或者函數(shù)與基本
工作空間之間傳遞數(shù)值,嘗試以下方法:
1、使用全局變量,用global定義全局變量
2、使用evalin:
evalin('base','v=1;'); %在基本工作空間中執(zhí)行命令:v=1;
evalin('caller','v=1;');%在調(diào)用該函數(shù)的函數(shù)的工作空間中
執(zhí)行命令:v=1;
3、參數(shù)傳遞
4、使用assignin:
assignin('base','v',v); %將v賦給基本工作空間中的變量v;
assignin('caller','v',v); %將v賦給調(diào)用者工作空間中的變量v;
inline函數(shù)里面只能出現(xiàn)函數(shù)和參數(shù),要傳遞一個(gè)可變系數(shù),需要用evalin。
如:fzero('f(evalin(''base'',''x1(i)''),x3)',求解區(qū)間)

=================================== - [返回]
43).怎樣在Simulink中調(diào)用m文件?
函數(shù)m文件可以使用Function & Tables中的Fcn模塊。如果有多個(gè)輸入,
用Mux組合成一個(gè)向量,然后在Fcn模塊的Expression填
MyFunction(u(1),u(2))"。如果有多個(gè)輸出,用Demux分解成多個(gè)標(biāo)量。


=================================== - [返回]
44).Matlab中怎樣進(jìn)行數(shù)制轉(zhuǎn)換?
參見:hex2dec,oct2dec,bin2dec,dec2bin,dec2oct,dec2hex.

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

p文件是pre-parsed的縮寫,即matlab在第一次運(yùn)行某m文件時(shí),matlab把該
文件先編譯成一種matlab的pseudo-code,當(dāng)你再次運(yùn)行該m文件時(shí),節(jié)省了
parse的時(shí)間。

p文件可以離開m文件單獨(dú)運(yùn)行

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

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

=================================== - [返回]
46).在Matlab中有g(shù)oto語句嗎?
matlab中沒有提供goto,因?yàn)榻Y(jié)構(gòu)化程序設(shè)計(jì)不推薦使用goto,但在matlab
中,goto的功能可以部分用結(jié)構(gòu)化的異常處理機(jī)制來實(shí)現(xiàn),比如從多重循環(huán)
中跳出,具體代碼為:

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).請(qǐng)問matlab6.X的那個(gè)matlab server是做什么的?(matlab開機(jī)運(yùn)行問題)

如果你在安裝matlab時(shí)選擇了web server的話,在每次重新啟動(dòng)后系統(tǒng)
進(jìn)程中就會(huì)出現(xiàn)matlab/matlabserver兩個(gè)進(jìn)程,如果你不需要使用
matlab webserver服務(wù)的話,建議在安裝時(shí)不要選擇web server,
如果已經(jīng)安裝的話,可以在"控制面板->管理工具->服務(wù)"中找到
matlab webserver,然后把它disable掉。

=================================== - [返回]
48).Matlab中如何用鼠標(biāo)取得坐標(biāo)?

matlab中用ginput來取得圖像上的一點(diǎn)。注意:image()/imagesc()對(duì)象
的y軸是和一般圖的y軸反的。

如果復(fù)雜的話,可以在ButtonDownFcn中g(shù)et(0,'PointerLocation')
或者get(gcf,'Position');

=================================== - [返回]
49).Matlab中有階乘函數(shù)嗎?
matlab沒有提供直接的階乘函數(shù),但可以用prod(1:n)來求n!
用prod(1:2:2n-1)或者prod(2:2:2n)來求解n!!

=================================== - [返回]
50)..怎樣才能把Maltab學(xué)精?

"帶著問題學(xué),活學(xué)活用,學(xué)用結(jié)合,急用先學(xué),立竿見影,
在'用'字上狠下功夫。"

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


=================================== - [返回]
52)..Matlab中怎樣求變上限二重積分?

對(duì)于解析函數(shù),用兩次int即可。
如求x+y在0[返回]
53)..用符號(hào)積分算出來Ei是什么意思,怎樣求值?

Ei是maple中的指數(shù)積分函數(shù),表示exp(-x*t)/t^n對(duì)t從1到正無窮大的積分。
Ei(n,x) = int(exp(-x*t)/t^n, t=1..infinity)
用命令“mhelp Ei”可以查看詳細(xì)說明;用符號(hào)計(jì)算得到的不明白的函數(shù)都可以通過
mhelp命令得到幫助。
求Ei(1,2)可以用maple命令得到:str2num(maple('evalf(Ei(1,2))'))。

=================================== - [返回]
54)..Maltab中使用\n換行在notepad中顯示為小黑塊,為什么?(Randy Poe)

換行和回車是不同的,而且在不同的操作系統(tǒng),解釋也不相同。
\n一般會(huì)操作系統(tǒng)被翻譯成"行的結(jié)束",即LF(Line-Feed)
\r會(huì)被翻譯成"回車",即CR(Cariage-Return)
對(duì)于文本文件的新行,在UNIX上,一般用\n(LF)來表示,Mac上用\r(CR)來表示,
Windows上是用\n\r(CR-LF)來表示。

所以在matlab中使用\n來寫回車,在windows上打開會(huì)出現(xiàn)小方塊。如果想
避免這種情況,打開文件時(shí)使用t參數(shù):

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

=================================== - [返回]
55)..Matlab中能開多大數(shù)組?(Steven Lord)

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

=================================== - [返回]
56)..如何使用整型矩陣來節(jié)省內(nèi)存?(Duane Hanselman)

如下方法無需先生成一個(gè)double的數(shù)組,然后轉(zhuǎn)換為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

同時(shí)也可以使用repmat來實(shí)現(xiàn)上述功能:

>> repmat(int8(0),rc)


=================================== - [返回]
57).Matlab在P4芯片上無法啟動(dòng)的解決方案

如果不想安裝補(bǔ)丁,只能使用matlab -nojvm的形式啟動(dòng)
matlab,否則需要參照如下頁面的解決方案來安裝補(bǔ)丁:
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).如何求解對(duì)離散點(diǎn)的最優(yōu)橢圓擬合?(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中如何中斷當(dāng)前運(yùn)算?(FangQ)

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

=================================== - [返回]
60)).Matlab/Mathematica中如何檢查括號(hào)匹配?(FangQ)

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

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

如果你在執(zhí)行GUI時(shí)出現(xiàn)"handles not defined"的錯(cuò)誤時(shí),
打開GUIDE,把figure的HandleVisibility設(shè)置為on或者callback,
則你可以在各個(gè)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中的按鈕如何在運(yùn)行時(shí)移動(dòng)及改變大小?(FangQ)
使用selectmoveresize函數(shù),例如:

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

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

Matlab提供了非常豐富的迭代型矩陣求解器,方法包括CG,BiCG,BiCGSTAB,
CGS,GMRES,LSQR,MINRES,P-CG,QMR,SYMMLQ等,為了加快矩陣求解速度,還
提供了兩個(gè)Preconditioner函數(shù):luinc(不完全LU分解),和cholinc(不完全
Cholesky分解)。下面是一個(gè)使用GMRES求解方程Amat*x=rhs的一個(gè)簡(jiǎn)單例子:

[L2,U2] = luinc(Amat,1e-3);
tic
x=gmres(Amat,rhs,[],1e-6,100,L2,U2);
toc
登錄后免費(fèi)查看全文
立即登錄
App下載
技術(shù)鄰APP
工程師必備
  • 項(xiàng)目客服
  • 培訓(xùn)客服
  • 平臺(tái)客服

TOP

2