声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1064|回复: 1

[GUI界面] 关与数据传递求助

[复制链接]
发表于 2011-4-22 09:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

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

本帖被以下淘专辑推荐:

回复
分享到:

使用道具 举报

发表于 2011-4-22 10:21 | 显示全部楼层
方法很多,内嵌函数,setappdata,handles等
一个简单的小例子,希望对你有用
  1. function [] = GUI_1()
  2. % Demonstrate how to delete an entry from a uicontrol string.  
  3. % Creates a listbox with some strings in it and a pushbutton.  When user  
  4. % pushes the pushbutton, the selected entry in the listbox will be deleted.
  5. %
  6. % Suggested exercise:  Modify the GUI so when the user deletes a certain
  7. % string, the 'value' property is set to the previous string instead of to
  8. % the first string.
  9. %
  10. %
  11. % Author:  Matt Fig
  12. % Date:  7/15/2009

  13. S.fh = figure('units','pixels',...
  14.               'position',[500 500 200 260],...
  15.               'menubar','none',...
  16.               'name','GUI_1',...
  17.               'numbertitle','off',...
  18.               'resize','off');

  19. S.ls = uicontrol('style','list',...
  20.                  'unit','pix',...
  21.                  'position',[10 60 180 180],...
  22.                  'min',0,'max',2,...
  23.                  'fontsize',14,...
  24.                  'string',{'one';'two';'three';'four'});         
  25. S.pb = uicontrol('style','push',...
  26.                  'units','pix',...
  27.                  'position',[10 10 180 40],...
  28.                  'fontsize',14,...
  29.                  'string','Delete String',...
  30.                  'callback',{@pb_call,S});

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

  37. % We need to make sure we don't try to assign an empty string.
  38. if ~isempty(L{1})
  39.     L{1}(L{2}(:)) = [];  % Delete the selected strings.
  40.     set(S.ls,'string',L{1},'val',1) % Set the new string.
  41. end
复制代码

点评

赞成: 5.0
赞成: 5
受用了,正好自己用的到,谢谢哈!  发表于 2011-4-24 20:14
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-2 23:50 , Processed in 0.175214 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表