iamacrazymonkey 发表于 2011-4-22 09:14

关与数据传递求助

    本人刚接触matlab,遇到了些问题,请各位大侠帮忙
   我在一个按钮的callback那里需要调用一个另外已经编好的程序,但是我不知道怎么把界面上输入的数据,使用到那个程序里....

qibbxxt 发表于 2011-4-22 10:21

方法很多,内嵌函数,setappdata,handles等
一个简单的小例子,希望对你有用function [] = GUI_1()
% Demonstrate how to delete an entry from a uicontrol string.
% Creates a listbox with some strings in it and a pushbutton.When user
% pushes the pushbutton, the selected entry in the listbox will be deleted.
%
% Suggested exercise:Modify the GUI so when the user deletes a certain
% string, the 'value' property is set to the previous string instead of to
% the first string.
%
%
% Author:Matt Fig
% Date:7/15/2009

S.fh = figure('units','pixels',...
            'position',,...
            'menubar','none',...
            'name','GUI_1',...
            'numbertitle','off',...
            'resize','off');

S.ls = uicontrol('style','list',...
               'unit','pix',...
               'position',,...
               'min',0,'max',2,...
               'fontsize',14,...
               'string',{'one';'two';'three';'four'});         
S.pb = uicontrol('style','push',...
               'units','pix',...
               'position',,...
               'fontsize',14,...
               'string','Delete String',...
               'callback',{@pb_call,S});

            
            
function [] = pb_call(varargin)
% Callback for pushbutton, deletes one line from listbox.
S = varargin{3};% Get the structure.
L = get(S.ls,{'string','value'});% Get the users choice.

% We need to make sure we don't try to assign an empty string.
if ~isempty(L{1})
    L{1}(L{2}(:)) = [];% Delete the selected strings.
    set(S.ls,'string',L{1},'val',1) % Set the new string.
end
页: [1]
查看完整版本: 关与数据传递求助