织梦CMS - 轻松建站从此开始!

罗索

matlab 的扩展编程1 用户图象界面

jackyhwei 发布于 2010-01-05 21:35 点击:次 
确切讲这应该算是matlab 的入门级教程,拿出来跟大家一起来共享,一起来学习。
TAG:

1 消息对话框 :msgbox
 
语法 :msgbox(message,title,icon)
message 为消息内容, title 为标题 icon 为图标  以上要用 '  '  括起来 .
    通过指定 icon 为'custom' ,就可以定制要显示的图标,如
data=1:64; data=(data'*data)/64;
h=msgbox('hello','test','custom',data,hot(64))
hot :HOT    Black-red-yellow-white color map
 
警告对话框: warndlg
语法:
warndlg(warnstring,dlgname)
warndlg('this is a warn','warn')
 
 
输入对话框 inputdlg
语法:
answer = inputdlg(prompt);
ex:
x=inputdlg('please input x:')
完全调用格式:
answer =inputdlg (prompt, title, lineno,defans,addopts);
prompt 提示语字符串,当有多个多个变量需要输入时,应该为每个变量写出提示语,用cell形式指定,即 ('prompt1','prompt2',...)
lineno:    指定输入参数编辑框的行和列数, 一般为1可, 如果都要指定用 [a,b]
defans :  输入参数的默认值.
addopts: 指定对话框的大小是否可以改变,为yes or no 
进度指示条:waitbar

h=waitbar(x,prompt);
x 0到1的小数,prompt为进度条的提示.

h=waitbar(0,'please wait...');
>> for i=1:100, waitbar(i/100,h)
pause(0.05)
end

list box
List box 可以实现条目的多选,单选和多选是由min和max两个属性控制的, 当 max-min>1的时候就可以实现多选功能了,由于min通常是0 ,只要将max设置为2就可以了.


  为控件指定弹出式菜单


每个控件都可以指定弹出式菜单,  可以通过控件的属性 uicontextmenu来设定,

 

回调函数
  callback 与控件相关的标准回调函数,不同的控件可以响应不同的事件, 尽管有相同的属性名,但是其实现代功能却因控件的不同而不同.

 


正弦信号分析器:

 

pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

f1 = str2double(get(handles.f1_input,'String'));
f2 = str2double(get(handles.f2_input,'String'));
t = eval(get(handles.t_input,'String')); %执行有字符串构成的表达式
x = sin(2*pi*f1*t) + sin(2*pi*f2*t);
y = fft(x,512);
m = y.*conj(y)/512;
f = 1000*(0:256)/512;
axes(handles.frequency_axes)
plot(f,m(1:257))
set(handles.frequency_axes,'XMinorTick','on')


grid on
% Create time plot
axes(handles.time_axes)
plot(t,x)
set(handles.time_axes,'XMinorTick','on')
grid on

 

一个模态对话框:
user_response = modaldlg('Title','Confirm Close');
switch lower(user_response)
case 'no'
 % take no action
case 'yes'
 % Prepare to close GUI application window
 %                  .
 %                  .
 %                  .
 delete(handles.figure1)
end

调用  modaldlg 的一个gui函数


%%%%%%%%%%%
 
 
 
 
求 两个向量之间的距离
pdist 这个函数功能很强大的 下面是help的内容
 
help pdist
 PDIST Pairwise distance between observations.
    Y = PDIST(X) returns a vector Y containing the Euclidean distances
    between each pair of observations in the N-by-P data matrix X.  Rows of
    X correspond to observations, columns correspond to variables.  Y is a
    1-by-(N*(N-1)/2) row vector, corresponding to the N*(N-1)/2 pairs of
    observations in X.
 
    Y = PDIST(X, DISTANCE) computes Y using DISTANCE.  Choices are:
 
        'euclidean'   - Euclidean distance
        'seuclidean'  - Standardized Euclidean distance, each coordinate
                        in the sum of squares is inverse weighted by the
                        sample variance of that coordinate
        'cityblock'   - City Block distance
        'mahalanobis' - Mahalanobis distance
        'minkowski'   - Minkowski distance with exponent 2
        'cosine'      - One minus the cosine of the included angle
                        between observations (treated as vectors)
        'correlation' - One minus the sample linear correlation between
                        observations (treated as sequences of s).
        'spearman'    - One minus the sample Spearman's rank correlation
                        between observations (treated as sequences of s).
        'hamming'     - Hamming distance, percentage of coordinates
                        that differ
        'jaccard'     - One minus the Jaccard coefficient, the
                        percentage of nonzero coordinates that differ
        'chebychev'   - Chebychev distance (maximum coordinate difference)
              - A distance specified using @, for
                        example @DISTFUN
 
    A distance must be of the form
 
          D = DISTFUN(XI, XJ, P1, P2, ...),
 
    taking as arguments a 1-by-P vector XI containing a single row of X, an
    M-by-P matrix XJ containing multiple rows of X, and zero or more
    additional problem-dependent arguments P1, P2, ..., and returning an
    M-by-1 vector of distances D, whose Kth element is the distance between
    the observations XI and XJ(K,:).
 
    Y = PDIST(X, DISTFUN, P1, P2, ...) passes the arguments P1, P2, ...
    directly to the DISTFUN.
 
    Y = PDIST(X, 'minkowski', P) computes Minkowski distance using the
    positive scalar exponent P.
 
    The output Y is arranged in the order of ((1,2),(1,3),..., (1,N),
    (2,3),...(2,N),.....(N-1,N)), i.e. the lower left triangle of the full
    N-by-N distance matrix in column order.  To get the distance between
    the Ith and Jth observations (I < J), either use the formula
    Y((I-1)*(N-I/2)+J-I), or use the helper Z = SQUAREFORM(Y),
    which returns an N-by-N square symmetric matrix, with the (I,J) entry
    equal to distance between observation I and observation J.
 
    Example:
 
       X = randn(100, 5);                 % some random points
       Y = pdist(X, 'euclidean');         % unweighted distance
       Wgts = [.1 .3 .3 .2 .1];           % coordinate weights
       Ywgt = pdist(X, @weucldist, Wgts); % weighted distance
 
       d = weucldist(XI, XJ, W) % weighted euclidean distance
       d = sqrt((repmat(XI,size(XJ,1),1)-XJ).^2 * W');

(jacky)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201001/8240.html]
本文出处:网络博客 作者:jacky
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容