⑴ 如何找出MATLAB的工具箱源代碼
有一些寫成動態庫的,你就看不見代碼了。
你可以試一下,輸入
edit 命令名
比方說:
edit rgb2gray
這個是可以看見代碼的。
而edit sqrt
會提示錯誤。
⑵ 如何查看matlab工具箱內置函數源代碼
有幾種方法可以實現查看matlab里自帶函數的源代碼:
在命令窗口中輸入:
(1)、type 函數名(如 type rgb2gray 或者 type rgb2gray.m):即可在命令窗口中顯示此函數的源代碼;
(2)、open 函數名(如 open rgb2gray 或者 open rgb2gray.m):即可打開rgb2gray.m文件;
(3)、edit 函數名(如 edit rgb2gray 或者 edit rgb2gray.m):即可打開rgb2gray.m文件;
(4)、還有一種方法就是故意將原有函數的參數或類型寫錯,它就會提示錯誤,然後點擊提示錯誤處,也可打開m文件,如:
rgb2gray(f, 3);%f為彩色圖像文件名,後面的3是隨意加上去的,因為函數rgb2gray原本就一個參數,現在為2個,肯定會報錯
rgb2gray(f, 3);
??? Error using ==> iptchecknargin at 77
Function RGB2GRAY expected at most 1 input argument
but was called instead with 2 input arguments.
Error in ==> rgb2gray>parse_inputs at 76 %點擊此處即可打開m文件
iptchecknargin(1,1,nargin,mfilename);
Error in ==> rgb2gray at 35 %點擊此出也可打開m文件
X = parse_inputs(varargin{:});
不過,一些比較底層的源代碼是看不見得。
⑶ 急求 matlab中函數ployfit的源代碼! 我的matlab(2007b版)好像是工具箱不完全,沒有ployfit這個函數~
function [p,S,mu] = polyfit(x,y,n)
%POLYFIT Fit polynomial to data.
% P = POLYFIT(X,Y,N) finds the coefficients of a polynomial P(X) of
% degree N that fits the data Y best in a least-squares sense. P is a
% row vector of length N+1 containing the polynomial coefficients in
% descending powers, P(1)*X^N + P(2)*X^(N-1) +...+ P(N)*X + P(N+1).
%
% [P,S] = POLYFIT(X,Y,N) returns the polynomial coefficients P and a
% structure S for use with POLYVAL to obtain error estimates for
% predictions. S contains fields for the triangular factor (R) from a QR
% decomposition of the Vandermonde matrix of X, the degrees of freedom
% (df), and the norm of the resials (normr). If the data Y are random,
% an estimate of the covariance matrix of P is (Rinv*Rinv')*normr^2/df,
% where Rinv is the inverse of R.
%
% [P,S,MU] = POLYFIT(X,Y,N) finds the coefficients of a polynomial in
% XHAT = (X-MU(1))/MU(2) where MU(1) = MEAN(X) and MU(2) = STD(X). This
% centering and scaling transformation improves the numerical properties
% of both the polynomial and the fitting algorithm.
%
% Warning messages result if N is >= length(X), if X has repeated, or
% nearly repeated, points, or if X might need centering and scaling.
%
% Class support for inputs X,Y:
% float: double, single
%
% See also POLY, POLYVAL, ROOTS, LSCOV.
% Copyright 1984-2008 The MathWorks, Inc.
% $Revision: 5.17.4.10 $ $Date: 2008/06/20 08:00:56 $
% The regression problem is formulated in matrix format as:
%
% y = V*p or
%
% 3 2
% y = [x x x 1] [p3
% p2
% p1
% p0]
%
% where the vector p contains the coefficients to be found. For a
% 7th order polynomial, matrix V would be:
%
% V = [x.^7 x.^6 x.^5 x.^4 x.^3 x.^2 x ones(size(x))];
if ~isequal(size(x),size(y))
error('MATLAB:polyfit:XYSizeMismatch',...
'X and Y vectors must be the same size.')
end
x = x(:);
y = y(:);
if nargout > 2
mu = [mean(x); std(x)];
x = (x - mu(1))/mu(2);
end
% Construct Vandermonde matrix.
V(:,n+1) = ones(length(x),1,class(x));
for j = n:-1:1
V(:,j) = x.*V(:,j+1);
end
% Solve least squares problem.
[Q,R] = qr(V,0);
ws = warning('off','all');
p = R\(Q'*y); % Same as p = V\y;
warning(ws);
if size(R,2) > size(R,1)
warning('MATLAB:polyfit:PolyNotUnique', ...
'Polynomial is not unique; degree >= number of data points.')
elseif warnIfLargeConditionNumber(R)
if nargout > 2
warning('MATLAB:polyfit:RepeatedPoints', ...
['Polynomial is badly conditioned. Add points with distinct X\n' ...
' values or rece the degree of the polynomial.']);
else
warning('MATLAB:polyfit:RepeatedPointsOrRescale', ...
['Polynomial is badly conditioned. Add points with distinct X\n' ...
' values, rece the degree of the polynomial, or try centering\n' ...
' and scaling as described in HELP POLYFIT.']);
end
end
r = y - V*p;
p = p.'; % Polynomial coefficients are row vectors by convention.
% S is a structure containing three elements: the triangular factor from a
% QR decomposition of the Vandermonde matrix, the degrees of freedom and
% the norm of the resials.
S.R = R;
S.df = max(0,length(y) - (n+1));
S.normr = norm(r);
function flag = warnIfLargeConditionNumber(R)
if isa(R, 'double')
flag = (condest(R) > 1e+10);
else
flag = (condest(R) > 1e+05);
end
⑷ VB編寫的區域網聊天工具源代碼
用VB做聊天程序的方法
---- 所謂"聊天"是指兩個程序能夠發送數據給對方。這個程序涉及到數據通訊的知識,彷彿很復雜,不過,由於VB給我們提供了一個Winsock控制項,問題就變得很簡單了。
---- 先編寫"聊天(主機)"程序。在窗體里添加Winsock控制項,並設置其Protocol屬性為1-SckUDPProtocol,其他屬性為預設值。接著添加兩個標簽和兩個文本框,設置兩個標簽的標題屬性分別為"接收窗"和"發送窗";兩個文本框的標題屬性為空。最後編寫代碼:
---- 1."聊天(主機)"
Private Sub Form-Load()
′設置網路地址
Winsock1.LocalPort=1024
Winsock1.RemoteHost="202.96.6.1"
Winsock1.RemotePort=1999
End Sub
Private Sub Text1-Change()
′發送用戶輸入的內容
Winsock1.SendData Text1.Text
End Sub
Private Sub Winsock1-DataArrival
(Byval bytesTotal As Long)
Dim rec As String
′接收對方數據並在文本框內顯示
Winsock1.GetData rec, vb String
Text2.Text=rec
End Sub
---- 2."聊天(副機)"
Private Sub Form_Load()
′設置網路地址
Winsock1.LocalPort=1999
Winsock1.RemoteHost="202.96.6.1"
Winsock1.RemotePort=1024
---- 其他部分程序與(主機)相同。最後將兩個程序存檔,並編譯成執行(.Exe)文件。現在就可以使用這個程序進行對話了。
---- 七.文本框中文本的某一特定字元或字元串同時高亮顯示的方法
---- 由於普通TextBox控制項不支持不連續字元串的同時高亮顯示,所以我們選擇RichTextBox控制項。單擊工程(Project)選單項,在彈出的下拉選單中單擊組件(Components)選單項,從彈出的對話框中選擇Microsoft Rich Textbox Control 5.0復選框,確定載入RichTextBox控制項。
---- 新建(New)一個工程,在窗體(Form)上添加一個RichTextBox控制項和兩個Command(按鈕)控制項,都採用系統默認的Name屬性值;設置RichTextBox的Text屬性值為空,Command1和Command2的Caption屬性值分別設為"輸入文本"和"選擇字元串"。最後,添加如下VB代碼:
Private Sub Command1-Click()
Dim str As String
Dim Text As String
str=〃輸入文本〃
Text=InputBox(str)
RichTextBox1.Text=Text
End Sub
Private Sub Command2-Click()
Dim str As String
Dim Text As String
Dim Position As Integer
Dim Lenth As Integer
str=〃輸入要高亮顯示的字元串〃
Text=InputBox(str)
If Text 〈〉 〃〃 Then
Position=InStr(RichTextBox1.Text, Text)-1
Lenth=Len(Text)
RichTextBox1.SelStart=Position
RichTextBox1.SelLength=Lenth
RichTextBox1.SelColor=RGB(255,0,0)
Do While InStr(Position+Lenth+
1, RichTextBox1.Text, Text) 〈〉 0
Position=InStr(Position+Lenth+
1, RichTextBox1.Text, Text)-1
RichTextBox1.SelStart=Position
RichTextBox1.SelLength=Lenth
RichTextBox1.SelColor=RGB(255,0,0)
Loop
End If
End Sub
---- 按F5執行程序,單擊"輸入文本"按鈕,在彈出的對話框中輸入一些文本,確定後,剛剛輸入的文本將顯示在RichTextBox中;再單擊"選擇字元串"按鈕,在彈出的對話框中輸入你希望高亮顯示的字元串,確定後,RichTextBox中相應的字元串將以紅色高亮顯示。
---- 八.編程實現Windows 95/98操作系統熱啟動的方法
---- 要利用程序實現系統的重新啟動,可以在你的程序中調用API函數來實現。建一個子函數:(以VB為例)
Declare Function SystemParametersInfo Lib 〃
user32〃 Alias -
〃SystemParametersInfo〃 (ByVal uAction As Long,
ByVal uParam As Long,
ByVal lpvParam As Any, ByVal
fuWinIni As Long) As Long
Sub DisableCtrlAltDelete(bDisabled As Boolean)
Dim X As Long
X=SystemParametersInfo(97, bDisabled, CStr(1), 0)
End Sub
Call DisableCtrlAltDelete(true) ′禁止熱啟
Call DisableCtrlAltDelete(false) ′允許熱啟
---- 九.在Windows 95/ 98啟動後自動啟動程序的方法
---- 我們都知道在Windows 95/98的"開始"→"程序"選單下有一"啟動"選單項,當每次啟動Windows 95或Windows 98時,系統都會自動啟動放在"啟動"選單欄里的可執行程序。
---- 但目前有好多軟體,像解霸五、ICQ,以及大部分實時偵測病毒的軟體等等,安裝後,並沒有放在"啟動"選單里,也能在啟動操作系統時自動啟動。怎麼實現的呢?
---- 其實只要知道Windows注冊表的一些知識,這個問題就不能稱之為問題了。用滑鼠單擊"開始",打開開始選單,再單擊"運行",出現一對話框,然後輸入"regedit",確定後,會打開系統注冊表編輯器,找到HKEY-LOCAL-MACHINE? SOFTWARE?Microsoft?Windows?CurrentVersion?Run,加入你的程序的入口,就可以了。如果不知道怎麼加,就參考一下已經存在的鍵值。
---- 十. 如何把數據文件輸出到Text控制項中?如果數據量比較大,窗體滿屏也不夠大,怎麼解決?
---- 有一個比較簡單的方法,就是把數據放到一個文本框(Text)里,並在其中加上水平和垂直滾動條。具體實現步驟為:先在窗體(Form)里加入一個文本框,採用默認名Text1;然後,設置文本框Text1的屬性:Text屬性設置為空,MultiLine屬性設置為True,ScrollBars屬性設置為3-Both;接著添加如下VB代碼:
Private Sub Form-Load()
Dim Handle As Integer
Dim FileName As String
On Error GoTo ErrExit
begin:
′輸入要顯示的數據文件的名稱
FileName=InputBox$(〃Input Filename〃,
〃Open File〃)
On Error GoTo FileErr
Handle=FreeFile
Open FileName For Input As #Handle
′把數據文件中的數據輸出到文本框中
Text1.Text=Input$(LOF(Handle), Handle)
Close #Handle
Exit Sub
FileErr:
Dim ErrNum As Integer
If Err.Number=53 Then
ErrNum=MsgBox(〃File not exist〃,
vbOKCancel, 〃Error Information〃)
If ErrNum=1 Then
GoTo begin
Else
Exit Sub
End If
End If
MsgBox Err.Description, , 〃file open failed〃
ErrExit:
Exit Sub
End Sub
′使文本框充滿整個窗體
Private Sub Form-Resize()
Text1.Left=0
Text1.Top=0
Text1.Width=Form1.Width-100
Text1.Height=Form1.Height-400
End Sub
---- 通過這樣的處理,不僅能解決問題,而且用戶還可以在文本框中對數據進行編輯。
---- 十一.關聯文件列表框、目錄列表框和驅動器列表框的方法
---- 想做一個對話窗體,包含驅動器列表框、目錄列表框和文件列表框,並能實現三者的同步操作,怎麼做?這都是我們在實際應用中經常會遇到的問題,在VB中解決這個問題非常簡單,可以通過Path屬性的改變引發Change事件來實現。例如:
Sub Dir1-Change()
File1.Path=Dir1.Path
End Sub
---- 該事件過程使窗體上的目錄列表框Dir1和文件列表框File1產生同步。因為目錄列表框Path屬性的改變將產生Change事件,所以在Dir1-Change事件過程中,把Dir1.Path賦給File1.Path,就可以產生同步效果。類似地,增加下面的事件過程,就可以使三種列表框同步操作:
Sub Drive1-Change()
Dir1.Path=Drive1.Drive
End Sub
---- 該過程使驅動器列表框和目錄列表框同步,前面的過程使目錄列表框和文件列表框同步,從而使三種列表框同步,問題即可解決。